How to plot a piecewise in MATLAB?
2 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!