help-octave
[Top][All Lists]
Advanced

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

Re: if statement within function


From: Ploett Norbert
Subject: Re: if statement within function
Date: Mon, 24 Jan 2005 07:54:36 +0100

Ahn, 

> f(x)=[1;4]; When using a vector, the if statement is useless...

I think you are right. You need an individual decision of which branch of the 
function to use for each element of x.

> I don't want to pass each element, but want to use f(x) as a chunk, with a 
> given vector x. What should I do to cure this problem??

Try this:

function y=f(x)
 flags1 = (x>1);
 flags2 = (x<=1);
 
 y = ones(rows(x), columns(x)) .* flags1 + x.^2 .* flags2 ;
endfunction

So you build complementary matrices of flags for your cases of x(i,j)>1 and 
x(i,j)<=1 and then overlay the results.


Greets


Norbert

-------------------------------------------------------------
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
-------------------------------------------------------------



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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