help-octave
[Top][All Lists]
Advanced

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

Re: Easy about Matrices


From: Mike Miller
Subject: Re: Easy about Matrices
Date: Mon, 18 Apr 2005 18:55:38 -0500 (CDT)

On Mon, 18 Apr 2005, Quentin Spencer wrote:

I'm not completely sure if this is what you're looking for, but maybe this example helps:

x = randn(1,1000);
x_positive = x(find(x>=0));
x_negative = x(find(x<0));


That seems like it must have been an excellent answer for Alvaro. I have a related question. Suppose I have a vector like this:

X=[1, 3, 9, 2, 4, 2, 7, 5, 3, 2, 9, 7]';

And suppose I want the indices of all elements of X that are in this vector Y:

Y=[2, 3, 9]';

I can see how to do it with a loop...

index=find(X==Y(1)); for i=2:length(Y), index=[index ; find(X==Y(i))]; end

...but can it be done without a loop? (Also, my method is a little awkward and I wouldn't mind hearing about how I could do it better.)

Mike



-------------------------------------------------------------
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]