From: Erin on
Hi,
I have an array called image that has intensity values. So, for instance, it could be
image=[2,6;7,9];

I then have an array of points that correspond to indices of the array image, so for instance:

points=[1,1;1,2;2,1;2,2]; %each row is one point

I would like to get the values of the image at each of these points. I would usually do a for loop, something like

for i=1:size(points,1)
values(i)=image(points(i,1),points(i,2))
end

So this would yield values=[2,6,7,9];

But I am doing this for a big array so to save time I would like to avoid the for loop if at all possible. Is there any way to take advantage of the array functionality of matlab to do this without the loop?

Thanks!
From: David Young on
You can use sub2ind to do this:

image(sub2ind(size(image), points(:,1), points(:,2))).'
From: ImageAnalyst on
But you shouldn't use the word "image" for your variable name since it
will override the built-in function called image(). Call it
imageArray, rgbImage, grayImage, or something like that, but NOT image.
From: Erin on
"David Young" <d.s.young.notthisbit(a)sussex.ac.uk> wrote in message <hqt5q0$o1i$1(a)fred.mathworks.com>...
> You can use sub2ind to do this:
>
> image(sub2ind(size(image), points(:,1), points(:,2))).'

Awesome thanks a lot!
Erin