I have a 2D array, call it A
. I have two other 2D arrays, call them ix
and iy
. I would like to create an output array whose elements are the elements of A
at the index pairs provided by ix
and iy
. I can do this with a loop as follows:
for i=1:nx
for j=1:ny
output(i,j) = A(ix(i,j),iy(i,j));
end
end
How can I do this without the loop? If I do output = A(ix,iy)
, I get the value of A over the whole range of (ix)X(iy).