Spikes in my heaviside function/step functions

조회 수: 4 (최근 30일)
Samantha Zhao
Samantha Zhao 2019년 2월 26일
댓글: Samantha Zhao 2019년 3월 7일
I am trying to plot a simple unit step function (below) using the heaviside function.
x(t) =u(t)−u(t−2)
t = -10:.01:10;
x = heaviside(t) - heaviside(t-2);
plot(x)
The plot results in a unit step function with spikes at 4 and -3.
heavisideSpikes.png
So far my solutions have been editing in the correct values at the appropriate indexes, but it has been getting very tedious. What could be causing this issue? I am also using the 2018b edition and have not noticed this in previous versions.
  댓글 수: 2
Asad Mirza
Asad Mirza 2019년 2월 26일
편집: Asad Mirza 2019년 2월 26일
Not sure why but when I run the code it comes out without any strange spikes. I am also using MATLAB 2018b.
Just checked it with both MATLAB Online and Octave and I get the same results
Matlab Online.PNG
Octave Online.PNG
Walter Roberson
Walter Roberson 2019년 3월 1일
Also, be careful about what heaviside(0) means. See sympref('HeavisideAtOrigin')

댓글을 달려면 로그인하십시오.

답변 (1개)

Munish Raj
Munish Raj 2019년 3월 1일
Hello Samantha,
The plot in your picture is a mixture of two different plots. It has the intended heaviside as expected.
As you can notice, the y axis of the plot is from [-3 4]. However, the expected heaviside function is plotted in [1 0] on the y axis.
Also please make sure there is no previous plot.
Use the hold off command before plotting the heaviside function.
hold off
to make sure that a new plot is being plotted.
  댓글 수: 3
Munish Raj
Munish Raj 2019년 3월 7일
heavisideSpikes.png
The red highlighted plot is the heaviside plot that you are looking for.
The other parts are the extra plots, possibly from another plot function.
Samantha Zhao
Samantha Zhao 2019년 3월 7일
I have reinstalled Matlab, opened up a new script, and made sure that there is nothing else being plotted with my heaviside. I'm really at a loss expecially when others are able to produce a normal graph with the exact code!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Electrophysiology에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by