[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
function applied to each component in an if clause
From: |
sururi |
Subject: |
function applied to each component in an if clause |
Date: |
Tue, 11 Mar 2008 02:54:15 -0700 (PDT) |
I'm wondering if there is a practical way of applying a comparison operator
to each component of a vector..
function [y] = lambda(x)
y.=x*2;
endfunction
x = [1 2 3];
lambda(x)
ans =
2 4 6
this works ok. But something like:
function [y] = lom(x)
if(x<2)
y=x.*3;
else
y=x.*1;
endif
endfunction
fails drastically.
lom([1 1 1])
ans =
3 3 3
ok but, as soon as the conditions are mixed:
lom([1 1 2])
ans =
1 1 2
not the [3 3 2] as I had intended.
I guess this problem may be solved using a loop over the components:
for i=1:length(x)
...
endfor
but I'm wondering if Octave has a comparison operator that takes care of
each component (smt like ".<")?
With my thanks in advance.
--
View this message in context:
http://www.nabble.com/function-applied-to-each-component-in-an-if-clause-tp15975728p15975728.html
Sent from the Octave - General mailing list archive at Nabble.com.