How to plot a piecewise in MATLAB?

6 ビュー (過去 30 日間)
Siddharth Garg
Siddharth Garg 2019 年 9 月 8 日
編集済み: Siddharth Garg 2019 年 9 月 8 日
I have this piecewise function and I have to plot this discrete signal using the stem function. This is what I wrote:
And this is the error I am getting:
What is it that I am doing wrong?
  1 件のコメント
Siddharth Garg
Siddharth Garg 2019 年 9 月 8 日
Note- In the 10th line, it should be: x<=-1

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

採用された回答

Star Strider
Star Strider 2019 年 9 月 8 日
I prefer the anonymous function approach:
x = @(n) n.*((0<=n) & (n<=8)) + 1*((-4<=n) & (n<=-1));
n = -10:12;
figure
stem(n, x(n))
grid

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by