MATLAB: Two for loops problem

for loops

Hi everyone,
here i want to get pixel intensity out of a 512*512 image.
i wrote two for loops, but in the end in matrix 'intensityValue', l got only the last set of data.
the background is to get the coordinates from x and y. corx and cory are 41*75 matrices.
Thanks !
fluo = imread('fluo0020.tif');
% imshow(fluo);
corx=[];
cory=[];
intensityValue=[];
for i=1:length(coordinate)
A = [coordinate ; coordinate(1,:)] ;
if mod(i, 2) == 1
x= int16(A(:,i));
y= int16(A(:,(i+1)));
corx=[corx,x];
cory=[cory,y];
end
% scatter(x,y);
% line(x,y);
% hold all
end
for ttt=1:length(x)
xc=x(ttt,:);
xy=y(ttt,:);
inten=fluo(xc,yc);
intensityValue =[intensityValue;inten];
end

Best Answer

You are directly use corx and cory variables to extract values from the matrix instead of the second for loop in your code.
intensityValue = fluo(sub2ind(size(fluo), cory, corx)); % cory is the row number and corx is the column number