How to plot a piecewise in MATLAB?

조회 수: 2 (최근 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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by