What is heaviside and how replace ?

2 views (last 30 days)
Hello,
I try to used a example plot.m find on Internet :
%%COURBE AVEC UN CRENEAU
figure
t=-20:20;
y = heaviside(t)
plot(t,y)
axis([-10 10 -2 2])
but the my Matlab R2015a say :
Undefined function or variable 'heaviside'. Error in Plot (line 130) y = heaviside(t)
and help don't find also
Please help Best regards Christophe

Accepted Answer

Stephen23
Stephen23 on 8 Oct 2015
Edited: Stephen23 on 8 Oct 2015
When you do a search of the documentation like this:
the green text underneath each search result tells you what toolbox or product that result applies to. The results of searching for "Heaviside" produces only results for the "Symbolic Math Toolbox", ergo heaviside is not a standard MATLAB function.
If you want a numeric version to use in MATLAB then try this anonymous function:
myHeaviside = @(V)(1+sign(V))/2;
which uses the H(0)==0.5 convention. Here it is used with your code:
>> myHeaviside = @(V)(1+sign(V))/2;
>> t = -20:20;
>> y = myHeaviside(t);
>> plot(t,y)
>> ylim([-0.1,1.1])
which produces this figure:

More Answers (1)

COTTINEAU Christophe
COTTINEAU Christophe on 8 Oct 2015
Excellent Thanks

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!