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 Exchange에서 Surfaces, 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