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: Olaf Till
Subject: Re: function applied to each component in an if clause
Date: Wed, 12 Mar 2008 13:53:14 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

On Wed, Mar 12, 2008 at 07:27:50AM +0100, Thomas Weber wrote:
> On 11/03/08 02:54 -0700, sururi wrote:
> > 
> > I'm wondering if there is a practical way of applying a comparison operator
> > to each component of a vector..
> 
> Use indices:
> 
> x = [0.5, 1, 2]
> lower = (x < 2)
> x(lower) = 4*x(lower)
> 
> In case someone else reads this: the last line above prints out all
> (three) elements of 'x'. I expected only the two matching elements of x.
> Is my expectation wrong?
Octave and matlab print out the contents of the whole variable to
which is assigned (without ;), even if you assign only to some
components. mmh --- this seams really not intuitive since in octave
the assignment itself has a value, which comprises only the assigned
components; if you type

a = x(lower) = 4*x(lower)

only the assigned components will be displayed.

Olaf


reply via email to

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