How to plot this stepfunction
이전 댓글 표시
Hello,
I am trying to plot a step function can be seen below. Any help will be highly appreciated. Thank you.

답변 (1개)
Star Strider
2018년 9월 23일
For the unit step function, you can use the Symbolic Math Toolbox heaviside function, or this anonymous function:
ustp = @(t) +(t>0); % Simple Unit Step Function
I leave the rest to you.
Remember to use element-wise operations for the multiplications. See the documentation page on Array vs. Matrix Operations (link) and Vectorization (link).
댓글 수: 4
Younes Alawaji
2018년 9월 23일
Star Strider
2018년 9월 23일
I will give you an illustration, and let you take it from here:
t = linspace(-10, 20, 1E+6);
f = @(t) sin(2*pi*t).*cos(2*pi*t*0.1);
figure
plot(t, f(t).*ustp(t-5))
grid
Note specifically the argument to ‘ustp’ with respect to the resulting plot.
Younes Alawaji
2018년 9월 23일
편집: Younes Alawaji
2018년 9월 23일
Star Strider
2018년 9월 23일
My pleasure.
My code is intended to illustrate how to combine the unit step function (my ‘ustp’ anonymous function) with another function to create the desired result. You cannot simply use it without modifying your code.
Also, you have to copy my ‘ustp’ function to the beginning of your script file. My code should then work.
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!