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 vect


From: mr_endres
Subject: Re: Two arrays specifying index pairs for a another array -- how to vectorize?
Date: Sat, 13 Mar 2010 06:21:51 -0800 (PST)


Jason-315 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.  
> ....
> 
> 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?
> 

Hello, 

you first have to convert the subscript-values in ix and iy to
indexed-values. Since the built-in function sub2ind only works for scalar
values, you have to build your own anonymous function; the following should
do the job:

toindex=@(x,y,r)r*(x-1)+y

With x,y the subscript-values and r the column-dimension of matrix A.

Then you should obtain out with:

out=A(toindex(ix(:),iy(:),size(A,2)))

I haven't checked that, but the idea should work ...


johannes
-- 
View this message in context: 
http://old.nabble.com/Two-arrays-specifying-index-pairs-for-a-another-array----how-to-vectorize--tp27885358p27887573.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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