MATLAB: Eliminating for-loops (compact notation?)

compact notationcomparing arrays

I am trying to compare fMRI images, but I seem to have quite an inefficient comparison algorithm.I have heard that efficiency gains can be made by using the slightly more native compact notation, but I have no idea where to start with this. Here is the code, it will end up being run several million times.
for xInd=1:xMax
for yInd=1:yMax
for zInd=1:zMax
if ~isnan(imageArray_1(1,xInd,yInd,zInd))
statImage(xInd,yInd,zInd)=abs(log(mean(imageArray_1(:,xInd,yInd,zInd)./imageNormalisationDivisor_1))-log(mean(imageArray_2(:,xInd,yInd,zInd)./imageNormalisationDivisor_2)));
end
end
end
end
Essentially there are 10 three-dimensional arrays per condition, and the difference in log mean value at each voxel across each condition is compared. Each image is normalised by dividing it by the mean value.
It's not a dealbreaker if it can't get much more efficient, I can leave it running for the day or so it would need, but I have a feeling that there are improvements that could be made.
Thanks, Matt

Best Answer

Oh, that's easy (just kidding):
X = squeeze(abs(log(mean(imageArray_1, 1)./mean(imageArray_2,1)*imageNormalisationDivisor_2/imageNormalisationDivisor_1)));
Note that the length of this one-liner is partly due to your long variable names. Compare
X = squeeze(abs(log(mean(I1, 1)./mean(I2,1)*s2/s1)));
To compare both solutions, use
max(abs(statImage(:) -X(:)))
That's not zero, but should be a small value in the range of eps, the machine precision.