help-octave
[Top][All Lists]
Advanced

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

Re: Select elements according to the index


From: Todd Neal
Subject: Re: Select elements according to the index
Date: Sun, 13 Feb 2005 10:04:11 -0600

On Sun, 13 Feb 2005 13:32:25 -0000, Chen, Minyu <address@hidden> wrote:
...
> Suppose I have an index matrix of 2 by 3, e.g. a=[1 2 3; 4 5 6]
> 
> And have a vector of 1 by 8, e.g. b=[.1 .2 .3 .4 .5 .6 .7 .8]
> 
> And I want to create a matrix c of 2 by 3 (the same dimension of a),
> with c(i,j)=b(a(i,j)), that's being said:
> 
> c=[.1 .2 .3; .4 .5 .6]
> 
> In matlab, as memory serves correctly, I can do it by typing:
> 
> c=b(a)
> 
> but this command in Octave will generate only a vector of 1 by 6:
> 
> c=[.1 .4 .2 .5 .3 .6]
> 
> How can I get the matrix I want?
> 
> Many Thanks,
> Minyu Chen

What version of Octave are you using ?  This is from 2.1.64 Debian Testing.

octave:1> a=[1 2 3; 4 5 6];
octave:2> b=[.1 .2 .3 .4 .5 .6 .7 .8];
octave:3> c=b(a)
c =

  0.10000  0.20000  0.30000
  0.40000  0.50000  0.60000


Todd



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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