|
From: | Carlo de Falco |
Subject: | Re: function applied to each component in an if clause |
Date: | Wed, 12 Mar 2008 11:02:50 +0000 |
On 12/mar/08, at 06:27, Thomas Weber wrote:
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?
Yes,As I understand it, the result of assigning a new value to some elements of x is the vector x with those values changed. So if you just drop the ";" at the end of the assignment statement you will get a print out of all x, while, if you do
x(lower) = 4*x(lower); x(lower) you will see only the first two elements. Matlab behaves the same way
Thomas
c.
[Prev in Thread] | Current Thread | [Next in Thread] |