Plotting discrete piecewise function

Need to plot a discrete piecewise function.But the problem is between 6 and 9 the value should be (2n+1).Can somebody please help me out
x = @(n) 3*((0<=n) & (n<=5)) + 2*n.*((6<=n) & (n<=9)) + 0*((n<0) & (n>9));
n = -12:12;
figure
stem(n, x(n))
grid

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 1 日

1 投票

x = @(n) 3*((0<=n) & (n<=5)) + (2*n+1).*((6<=n) & (n<=9)) + 0*((n<0) | (n>9));
n = -12:12;
figure
stem(n, x(n))
grid

カテゴリ

ヘルプ センター および File ExchangeSurfaces, Volumes, and Polygons についてさらに検索

質問済み:

2021 年 2 月 1 日

回答済み:

2021 年 2 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by