two arrays defining 2d coordinates, as array indices, in matlab/octave

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2010-03-12T18:50:06Z Indexed on 2010/03/12 18:57 UTC
Read the original article Hit count: 323

Filed under:
|
|
|

Hi,

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 x_idx and y_idx. 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).

Thank you, Jason

© Stack Overflow or respective owner

Related posts about matlab

Related posts about octave