-
Notifications
You must be signed in to change notification settings - Fork 2
/
art_slice_STD.m
72 lines (61 loc) · 1.94 KB
/
art_slice_STD.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function STDvol = art_slice_STD(P, orient, nscans, pq, Automask, vx, vy, vz)
% This function takes a list of filenames P and calculates a volume of the
% standard deviation of the timeseries without taking in consideration bad
% slices during calculation.
% D. Postina - 2012
for i = 1:nscans
thisvol = spm_read_vols(P(i));
Yn2 = squeeze(thisvol);
Y = ( 1 - Automask).*Yn2;
if ( orient == 1 )
py = mean(mean(Y,3),2);
for j = 1:vx
if py(j) > pq(j) % drop slice from variance calculation
allvols(i,j,:,:) = NaN;
else
allvols(i,j,:,:) = Yn2(j,:,:);
end
end
end;
if ( orient == 2 )
py = mean(mean(Y,1),3);
for j = 1:vy
if py(j) > pq(j) % drop slice from variance calculation
allvols(i,:,j,:) = NaN;
else
allvols(i,:,j,:) = Yn2(:,j,:);
end
end
end;
if ( orient == 3 )
py = mean(mean(Y,1),2);
for j = 1:vz
if py(j) > pq(j) % drop slice from variance calculation
allvols(i,:,:,j) = NaN;
else
allvols(i,:,:,j) = Yn2(:,:,j);
end
end
end;
end
temp = art_nanstd(allvols);
STDvol(:,:,:) = temp(1,:,:,:);
clear allvols;
function [fff_std] = art_nanstd(data);
%
% [f_std] = nanstd(data);
%
%Function which calculates the std (not NaN) of data containing
%NaN's. NaN's are excluded completely from calculation.
[m,n] = size(data);
for index = 1:n;
not_nans = find(isnan(data(:,index)) == 0);
if length(not_nans) > 0;
f_std(index) = std(data(not_nans,index));
else
f_std(index) = NaN;
end
end
% we have the 1xN array of STDs, lets put them in the volume
fff_std = zeros(1,size(data,2),size(data,3),size(data,4));
fff_std(:) = f_std(:);