help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two arrays specifying index pairs for a another array -- how to vec


From: Jaroslav Hajek
Subject: Re: Two arrays specifying index pairs for a another array -- how to vectorize?
Date: Sat, 13 Mar 2010 19:02:55 +0100

On Fri, Mar 12, 2010 at 8:06 PM, Jason <address@hidden> wrote:
> Hello,
>
> I have a 2D array, say 'A'.  I also have two 2D arrays, say 'ix' and 'iy'.  I
> would like to make a third 2D array, whose elements are the elements of A at 
> the
> index pairs specified by ix and iy.  I can do this with a loop as follows:
>
>    for i=1:nx
>        for j=1:ny
>            out(i,j) = A(ix(i,j),iy(i,j));
>        end
>    end
>
> Is there a way I can do this with matrix/vector operations? If I do
> out=A(ix,iy), that will give me an (nx*ny)X(nx*ny) array using all the 
> possible
> pairs of values in ix and iy.  Any ideas?
>
> Thank you,
> Jason
>
> __


out = A(sub2ind (size (A), ix, iy));


-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]