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.
  1 件のコメント
Fangjun Jiang
Fangjun Jiang 2018 年 10 月 3 日
Not clear.

サインインしてコメントする。

採用された回答

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 Center および File ExchangePie Charts についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by