matlab - Improve memory-inefficient script -


i have create probabilistic voxel map 5 individual maps binary maps containing either 1 or 0. let's call these individual maps x1, x2, x3, x4, x5. probabilistic map y = (x1 + x2 + x3 + x4 + x5)/5. thus, each voxel give me percentage of individual maps having 1 value voxel. instance, if value of voxel in y 0.4, tells me 40% of individual maps (2 individual maps) have 1 value particular voxel. issue have when number of individual maps increases, script becomes bulky. have

maindir=<where individual maps are> p={}; subj={'subj1','subj2','subj3','subj4','subj5'}  = 1:length(subj)    indv_roi=spm_select('fplist',fullfile(maindir),sprintf('^%s.*\\.img$',subj{a}));    p.(subj{a}) = spm_read_vols(spm_vol(indv_roi),1);    p.(subj{a})(isnan(p.(subj{a})))=0; end  y = (p.subj1+p.subj2+p.subj3+p.subj4+p.subj5)/5 

clearly inefficient. have suggestion how improve code? thank you.

i presume memory bottleneck?

instead of loading images memory and then calculating average, add voxel maps in loop , normalise in end. way, 1 image needs in memory @ given point:

y = init_empty_volume()  subj={'subj1','subj2','subj3','subj4','subj5'}  = 1:length(subj)    indv_roi=spm_select('fplist',fullfile(maindir),sprintf('^%s.*\\.img$',subj{a}));     x = spm_read_vols(spm_vol(indv_roi),1);    x(isnan(x))=0;     y = y + x;  end  y = y ./ length(subj) 

with init_empty_volume() mean either initialising empty matrix right dimensions, or loading example image , multiplying zero, whatever easier in case.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -