Plot unit step function

조회 수: 5 (최근 30일)
Corinne Dale
Corinne Dale 2018년 10월 3일
댓글: Star Strider 2023년 9월 19일
I'm trying to plot the signal u(t)-u(t-1) without heaviside in MATLAB. I've tried to use the if loop but couldn't figure it out.

채택된 답변

Star Strider
Star Strider 2018년 10월 3일
You can use a ‘logical indexing’ approach:
ustp = @(t) +(t>0); % Simple Unit Step Function
t = linspace(-5, 5);
figure
plot(t, ustp(t)-ustp(t-1))
grid
I will let you figure out how it works.
  댓글 수: 3
Vicky
Vicky 2023년 9월 19일
Can you explain how you wrote "@(t) +(t>0)"? It worked perfectly but I'm unsure what the @ is doing here. Thank you so much!
Star Strider
Star Strider 2023년 9월 19일
@Vicky — That is an anonymous function. It works the same way other functions do, and can be called similarly. The ‘@’ creates its function handle.
See the documentation on Anonymous Functions and What is a Function Handle? for details.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by