-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegression_of_Img2bhv.m
72 lines (59 loc) · 1.65 KB
/
Regression_of_Img2bhv.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
clear
clc
maskimg='E:\test\mask.nii';%mask file
maskimg=spm_vol(maskimg);
V=maskimg;
maskimg=spm_read_vols(maskimg);
Xdim=size(maskimg,1);
Ydim=size(maskimg,2);
Zdim=size(maskimg,3);
Imgdir='E:\test\Img';
Imgfolder=dir(Imgdir);
Imgfolder=Imgfolder(3:end);
Img=zeros(length(Imgfolder),Xdim*Ydim*Zdim);
behavior1=textread('E:\test\age.txt');
behavior2=textread('E:\test\sex.txt');
%behavior3=xxx
%behavior4=xxx
%······
%behavior(n)=xxx
for i=1:length(Imgfolder);
Imgfile=[Imgdir,'\',Imgfolder(i).name];
Imgfile=spm_vol(Imgfile);
Imgfile=spm_read_vols(Imgfile);
Imgfile=Imgfile.*maskimg;
Img(i,:)=reshape(Imgfile,1,Xdim*Ydim*Zdim);
end
for j=1:Xdim*Ydim*Zdim;
X=[ones(size(behavior1)) behavior1 behavior2];%X=[ones(size(behavior1)) behavior1 behavior2 ··· behavior(n)]
Y=[Img(:,j)];
[B,BINT,R,RINT,STATS] = regress(Y,X);
STATS1(j)=STATS(1);
STATS2(j)=STATS(2);
STATS3(j)=STATS(3);
STATS4(j)=STATS(4);
end
STATS1(find(isnan(STATS1)))=0;
STATS2(find(isnan(STATS2)))=0;
STATS3(find(isnan(STATS3)))=0;
STATS4(find(isnan(STATS4)))=0;
STATS1=reshape(STATS1,Xdim,Ydim,Zdim);
STATS2=reshape(STATS2,Xdim,Ydim,Zdim);
STATS3=reshape(STATS3,Xdim,Ydim,Zdim);
STATS4=reshape(STATS4,Xdim,Ydim,Zdim);
VV=V(1);
VV.fname=['E:\test\STATS1.nii'];
VV.dt=[16 1];
VV = spm_write_vol(VV,STATS1);
VV=V(1);
VV.fname=['E:\test\STATS2.nii'];
VV.dt=[16 1];
VV = spm_write_vol(VV,STATS2);
VV=V(1);
VV.fname=['E:\test\STATS3.nii'];
VV.dt=[16 1];
VV = spm_write_vol(VV,STATS3);
VV=V(1);
VV.fname=['E:\test\STATS4.nii'];
VV.dt=[16 1];
VV = spm_write_vol(VV,STATS4);