-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmysavespm.m
More file actions
70 lines (62 loc) · 2.17 KB
/
mysavespm.m
File metadata and controls
70 lines (62 loc) · 2.17 KB
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
%==========================================================================
function mysavespm(action,fname) % function from spm_results_ui
%==========================================================================
xSPM = evalin('caller','xSPM;');
XYZ = xSPM.XYZ;
switch lower(action)
case 'thresh'
Z = xSPM.Z;
case 'binary'
Z = ones(size(xSPM.Z));
case 'n-ary'
if ~isfield(xSPM,'G')
Z = spm_clusters(XYZ);
num = max(Z);
[n, ni] = sort(histc(Z,1:num), 2, 'descend');
n = size(ni);
n(ni) = 1:num;
Z = n(Z);
else
C = NaN(1,size(xSPM.G.vertices,1));
C(xSPM.XYZ(1,:)) = ones(size(xSPM.Z));
C = spm_mesh_clusters(xSPM.G,C);
Z = C(xSPM.XYZ(1,:));
end
case 'current'
[xyzmm,i] = spm_XYZreg('NearestXYZ',...
spm_results_ui('GetCoords'),xSPM.XYZmm);
spm_results_ui('SetCoords',xSPM.XYZmm(:,i));
if ~isfield(xSPM,'G')
A = spm_clusters(XYZ);
j = find(A == A(i));
Z = ones(1,numel(j));
XYZ = xSPM.XYZ(:,j);
else
C = NaN(1,size(xSPM.G.vertices,1));
C(xSPM.XYZ(1,:)) = ones(size(xSPM.Z));
C = spm_mesh_clusters(xSPM.G,C);
C = C==C(xSPM.XYZ(1,i));
Z = C(xSPM.XYZ(1,:));
end
otherwise
error('Unknown action.');
end
if isfield(xSPM,'G')
F = spm_input('Output filename',1,'s');
if isempty(spm_file(F,'ext'))
F = spm_file(F,'ext','.gii');
end
F = spm_file(F,'CPath');
M = gifti(xSPM.G);
C = zeros(1,size(xSPM.G.vertices,1));
C(xSPM.XYZ(1,:)) = Z; % or use NODE_INDEX
M.cdata = C;
save(M,F);
cmd = 'spm_mesh_render(''Disp'',''%s'')';
else
V = spm_write_filtered(Z, XYZ, xSPM.DIM, xSPM.M,...
sprintf('SPM{%c}-filtered: u = %5.3f, k = %d',xSPM.STAT,xSPM.u,xSPM.k),fname);
cmd = 'spm_image(''display'',''%s'')';
F = V.fname;
end
fprintf('Written %s\n',spm_file(F,'link',cmd)); %-#