I have a probability matrix(glcm) of size 256x256x20. I have reshaped the matrix to 65536x20, so that I can eliminate one loop (along the 3rd dimension).
I want to do the following calculation.
for y = 1:256
for x = 1:256
if (ismember((x + y),(2:2*256)))
p_xplusy((x+y),:) = p_xplusy((x+y),:) + glcm(((y-1)*256+x),:);
end
end
end
So the p_xplusy will be a 511x20 matrix which each element is the sum of the diagonal of nxn sub matrix (where n belongs to 1:256) of the original 256x256x20 matrix.
This code block is making my program inefficient and I want to vectorize this loop. Any help would be appreciated.
ismemberis a rather expensive function call. Just looking at this it looks like you could replace yourif (ismember((x + y),(2:2*256)))line withif x+y<=2*256 && x+y>1. What I'm suggesting isn't vectorizing but it could speed this code up a LOT. - chessofnerd" p_xplusy will be a 511x20", but it threw me an error with it, assumingrandvalues. I had to make itrand(512,20)to make it work. Could you clarify on this? - Divakar