From help-request at octave dot org Tue Apr 19 04:20:56 2005 Subject: Re: Easy about Matrices From: "Peter Bodin" To: help at octave dot org Date: Tue, 19 Apr 2005 11:17:21 +0200 (CEST) > Frank Palazzolo wrote: > >>This syntax works as well: >> >>x = randn(1,1000); >>x_positive = (x>=0); >>x_negative = (x<0); >> >>I'm not sure if it's any more efficient, but it seems it would be, >> since it >>never needs to build an explicit index vector. >> >>-Frank >> >> > This is definitely faster, but it doesn't return the same matrix: > > octave:1> x=randn(1,10); > octave:1> (x>0) > ans = > > Columns 1 through 8: > 1 1 0 0 0 0 1 > 0 > Columns 9 and 10: > 1 1 > > octave:3> x(find(x>0)) > ans = > > 0.93970 0.38451 0.30387 0.81479 2.46831 > > > > > ------------------------------------------------------------- > 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 > ------------------------------------------------------------- > > Hi! Why not use logical indexing? x(x>0) or am I missing the obvoius here? /PB ------------------------------------------------------------- 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 -------------------------------------------------------------