Another one on "Structure assignment to non-structure object."
Afficher commentaires plus anciens
The error happens at line 66:
Subject 002_S_0295_2012-05-10
Structure assignment to non-structure object.
Error in map_rest_data_to_power264_Copy (line 66)
sampMask(iRoi).roi = distMat < sphere_radius_mm/voxel_sz + shellThickness/voxel_sz;
And here is the code:
1 % Map output of SPM preprocessing to Power's 264 Nodes parcellation scheme
2 clearvars;
3 % close all;
4 clc
5
6
7 % Input data path
8 data_path = 'E:/ADNI/Preprocessed_test/FunImgARWS/';
9 output_dir = 'E:/ADNI/Preprocessed_test/Output/';
10
11 % Get list of all subjects
12 list_subj = dir([data_path,'00*']);
13 nSubj = length(list_subj);
14 nscans = 6720;
15 d =264; % this is the number of nodes in Power template
16
17 % Read the 264 ROI positions defined by Power
18 [numval_power,txt,raw] = xlsread('C:/Users/dkarletsos/Box Sync/Tulane/TCBG/AD/issues with preprocessing/biao_voxels/mmc2.xls');
19
20
21
22
23 for iSubj =1:nSubj
24 % tic
25 if(~exist([output_dir,'rest_',list_subj(iSubj).name,'.mat'],'file'))
26 if(exist([data_path,list_subj(iSubj).name],'dir'))
27
28 nii_path = [data_path,list_subj(iSubj).name,'/'];
29
30 if(exist([nii_path,'rp_scan_001.txt'],'file'))
31
32 fprintf('Subject %s\n',list_subj(iSubj).name);
33
34 % Read all 3d nii files
35 list_nii = dir([nii_path,'swra*.nii']);
36
37 % read motion values
38 if(exist([nii_path,'rp_scan_001.txt'],'file'))
39 motion_val = dlmread([nii_path,'rp_scan_001.txt']);
40 motion_val = motion_val-repmat(mean(motion_val),[size(motion_val,1),1]);
41 else
42 error('Motion file could not be read!');
43 end
44
45 % Compute image grid (check according to SPM output dimensions)
46 [xMat,yMat,zMat] = ndgrid(1:61,1:73,1:61);
47
48 % Initialize array to store time-serie data % not sure what
49 % the 70 figure is
50 img_time_serie = zeros(264,140,length(list_nii));
51
52 % convert MNI coordinates to voxel grid coordinates
53 vox_idx = mm2vox(numval_power(:,2:4),[nii_path,list_nii(1).name]);
54
55 sphere_radius_mm = 5; % radius spheres
56 voxel_sz = 2; % voxels are 2x2x2mm
57
58 sampMask = cell(size(numval_power,1));
59
60 % Get i for each ROI
61 for iRoi =1:size(numval_power,1)
62 c = vox_idx(iRoi,:); % XYZ of center of sphere
63 distMat = sqrt((xMat-c(1)).^2 + (yMat-c(2)).^2 + (zMat-c(3)).^2);
64 shellThickness = 0.1; % Ie, only sample pixels within shellThickness-mm of a perfect sphere
65 %sampMask{iRoi} = distMat < sphere_radius_mm/voxel_sz + shellThickness/voxel_sz;
66 sampMask(iRoi).roi = distMat < sphere_radius_mm/voxel_sz + shellThickness/voxel_sz;
67 %
68 % sampMask{iRoi} = abs(distMat - sphere_radius_mm/voxel_sz) < shellThickness/voxel_sz;
69 end % end ROI
70
71 % Loop through each scan
72 dat_4d_full = zeros(61,73,61,length(list_nii));
73 for iScan =1:length(list_nii)
74 nii_img = load_nii([nii_path,list_nii(iScan).name]);
75 dat_4d_full(:,:,:,iScan) = nii_img.img;
76 end
77 % Loop through each ROI
78 for iRoi =1:size(numval_power,1)
79 sampPx = dat_4d_full(repmat(logical(sampMask{iRoi}),[1,1,1,nscans]));
80 sampPx = reshape(sampPx,[nnz(sampMask{iRoi}),nscans])';
81
82 % Detrend data (in time)
83 Xtrend = [ones(nscans,1),[1:nscans]',([1:nscans].^2)'];
84 for i_vox =1:size(sampPx,2)
85 b = regress(sampPx(:,i_vox),Xtrend);
86 sampPx(:,i_vox) = sampPx(:,i_vox) - Xtrend*b;
87 end
88
89 % Whiten data
70 [Xwh, mu, invMat, whMat] = whiten(sampPx);
71 img_time_serie(iRoi,:,:) = Xwh';
72 end
73
74 % Regress effect of motion
75 img_time_serie = img_time_serie -repmat(mean(img_time_serie,2),[1,size(img_time_serie,2)]);
76 img_time_serie = img_time_serie';
77 img_time_serie_moco = zeros(size(img_time_serie));
78 for iRoi =1:size(img_time_serie,2)
79 b = regress(img_time_serie(:,iRoi),motion_val);
80 img_time_serie_moco(:,iRoi) = img_time_serie(:,iRoi) - motion_val*b;
81 end
82 img_time_serie = img_time_serie_moco';
83 %%
84 % % Filter data using band pass butterworth filter
85 % img_time_serie = img_time_serie -repmat(mean(img_time_serie,2),[1,size(img_time_serie,2)]);
86 % lowFreq =0.01;
87 % hiFreq =0.1;
88 % fs =1/3;
89 % order = 5;
90 % [b,a] = butter(order, [lowFreq hiFreq]/(fs/2), 'bandpass');
91 % img_time_serie = filter(b,a,img_time_serie,[],2);
92 %
93 % % % correlation matrix
94 % % RHO = corr(img_time_serie');
95 % % figure()
96 % % subplot(121),imagesc(RHO)
97 % % subplot(122),histogram(RHO(:))
98 %%
99 save([output_dir,'/rest_',list_subj(iSubj).name,'.mat'],'img_time_serie','motion_val');
100 end
101 end
102 end
103 % toc
104 end
4 commentaires
Geoff Hayes
le 12 Déc 2020
Dimitris - why are you considering sampMask(iRoi) to be a structure with a field called roi when it is really just a cell within a cell array? Why not just do
sampMask(iRoi) = distMat < sphere_radius_mm/voxel_sz + shellThickness/voxel_sz;
?
Dimitris Karletsos
le 12 Déc 2020
Walter Roberson
le 12 Déc 2020
sampMask{iRoi} = distMat < sphere_radius_mm/voxel_sz + shellThickness/voxel_sz;
Dimitris Karletsos
le 12 Déc 2020
Réponses (0)
Catégories
En savoir plus sur Neuroimaging dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!