Hi all,
I'm writing a function that defines a sphere (center and radius are part of the inputs of the function), takes an fMRI scan file then finds the average activation value of all the voxels within that sphere. Below is what I do:
my_sphere = make_sphere(s,r)
center = [i, j, k];
my_sphere = bsxfun(@plus, my_sphere, center);
Data2Read=fullfile(datadir,fname);
a=spm_vol(Data2Read);
v=spm_read_vols(a);
theSum = 0;
count = 0;
for h = 1:size(my_sphere, 2)
theSum = theSum + v(my_sphere(h,1), my_sphere(h,2), my_sphere(h,3));
count = count + 1;
end
MeanActivation = theSum / count
Since it is possible that part of the sphere may fall outside the brain (i.e. outside of the space defined in the scan file), I imagine values in this part of the sphere would be NAN. Thus, when taking the average, I could perhaps use isnan() to exclude these NANs from the average. However, whenever I encounter such scenarios, I only get an error message (Example: ??? Attempted to access v(11,77,63); index out of bounds because size(v)=[72,72,33].). Could anyone help?