[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: function values vector
From: |
Jaroslav Hajek |
Subject: |
Re: function values vector |
Date: |
Fri, 14 May 2010 15:44:46 +0200 |
On Fri, May 14, 2010 at 3:36 PM, mmasny <address@hidden> wrote:
>
> Hello, I'm a complete newbie, and after reading several tutorials still
> haven't solved the following problem:
> I have a vector x=linspace(0,2*pi,256). There is a function H given as
> follows:
>
> function y=H(x)
> if (x<pi)
> y=0;
> else
> y=1;
> endif
> end
>
> Now, I want a vector Y such that each of its coordinates xi is H(xi). What's
> the best way to that? Y=H(X) doesn't work (it makes Y=1, which I don't
> understand). Do I need a loop to do that?
y = pi*(x >= pi);
or in 3.3.51+, a more powerful construct is
y = ifelse (x < pi, 0, 1);
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz