[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "table too short" error while trying to plot a function
From: |
Martin Helm |
Subject: |
Re: "table too short" error while trying to plot a function |
Date: |
Fri, 14 May 2010 12:09:46 +0200 |
User-agent: |
KMail/1.12.4 (Linux/2.6.31.12-0.2-desktop; KDE/4.3.5; x86_64; ; ) |
Am Freitag, 14. Mai 2010 02:21:31 schrieb Leo Arias F.:
> Hello,
>
> I'm new with this. I'm just learning with the matlab guide.
>
> I followed the guide in [1] and could plot the humps funtion without
> problems.
>
> But I defined my own function on the functiontest1.m file:
> function y = functiontest1(x)
> if abs(x)<1
> y = 1;
> elseif 1 < abs(x) && abs(x) < 2
> y = 2 - abs(x);
> else
> y = 0;
> end
>
> And when I try to plot it:
> octave3.2:1> fplot(@functiontest1, [-3 3])
>
> I get the following error:
> error: interp1: table too short
> error: called from:
> error: /usr/share/octave/3.2.3/m/general/interp1.m at line 143, column 5
> error: /usr/share/octave/3.2.3/m/plot/fplot.m at line 86, column 11
>
> Could you please tell me what I'm doing wrong?
>
> thanks :)
> pura vida
>
> [1]
> http://www.mathworks.com/access/helpdesk/help/techdoc/math/bsgprpq-4.html
>
You will need to write your function in a vectorized form not in this scalar
form, for example something like
function y = functiontest1(x)
y=zeros(size(x));
i1 = abs(x)<1;
i2 = 1 < abs(x) & abs(x) < 2;
y(i1) = 1;
y(i2) = 2-abs(x(i2));
endfunction
Then it will work.
- mh