From help-request at octave dot org Mon Jan 24 00:56:33 2005 Subject: Re: if statement within function From: "Ploett Norbert" To: "Ahn Kyung" Cc: Date: Mon, 24 Jan 2005 07:54:36 +0100 Ahn,=20 > f(x)=3D[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=20 > given vector x. What should I do to cure this problem?? Try this: function y=3Df(x) flags1 =3D (x>1); flags2 =3D (x<=3D1); =20 y =3D 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)<=3D1 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 -------------------------------------------------------------