help-octave
[Top][All Lists]
Advanced

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

Re: function applied to each component in an if clause


From: sururi
Subject: Re: function applied to each component in an if clause
Date: Wed, 12 Mar 2008 02:04:44 -0700 (PDT)

Dear Michael and Thomas, thank you very much for your help.

and now, another question concerning Thomas' remark... 8)

When you assign 

lower = (x < 2)

you have a vector of trues and falses, right? So for 

x = [1 1.5 2 3]

you get the [1 1 0 0] vector. But unlike the "find" function Michael
suggested which would return the indices complying the criteria ([1 2] in
our case), you have a special type of vector. I'm thinking of this as
special because, when you extract the components, as in
x(lower), you get a real, what you intended, answer:

>x(lower)
ans =
   1.0000   1.5000

but how does the code know that this lower vector is special? Because:

octave:4> type lower
lower is a user-defined variable
[  1,  1,  0,  0 ]

octave:5> lower2 = [  1,  1,  0,  0 ]
lower2 =
   1   1   0   0

octave:6> type lower2
lower2 is a user-defined variable
[  1,  1,  0,  0 ]

octave:7> x(lower2)
error: invalid vector index = 0

i.e., when I construct the same vector as lower2 manually, this time the
code treats it as indices vector.

Best regards & thanks again,
Emre ST
-- 
View this message in context: 
http://www.nabble.com/function-applied-to-each-component-in-an-if-clause-tp15975728p16000148.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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