[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: function values vector
From: |
Francesco Potortì |
Subject: |
Re: function values vector |
Date: |
Mon, 17 May 2010 08:19:31 +0200 |
>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).
The esiest is to do this:
octave> x=linspace(0,2*pi,16)
x =
Columns 1 through 8:
0.00000 0.41888 0.83776 1.25664 1.67552 2.09440 2.51327 2.93215
Columns 9 through 16:
3.35103 3.76991 4.18879 4.60767 5.02655 5.44543 5.86431 6.28319
octave> Y = (x >= pi)
Y =
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
However, these are not really zeros and ones, but boolean values:
octave> typeinfo (Y)
ans = bool matrix
This is not normally a problem, on the contrary, it is usually what you
want and takes less memory space. Moreover, if you perform math
operations on them, they are converted to numbers. Anyway, if for some
reason you need real zeros and ones you can use double():
octave> typeinfo(double(Y))
ans = matrix
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/