how to get my plot to only go to the value of 'n' I have set

1 回表示 (過去 30 日間)
Anthony Walden
Anthony Walden 2022 年 6 月 18 日
コメント済み: Star Strider 2022 年 6 月 18 日
The below code plots out to well past the values of 'n' and I was wanting to limit it to just the range of 'n'. I saw something about using size(n) but I am not sure how and where to place it so that my plot only goes from 0 to 20 along the 'n' axis. Any help would be appreciated.
syms t;
n = 0:20;
N = 21;
% piecewise of x1 and x2 for unit pulse
x_n = [1, zeros(1,20)];
% discrete time unit pulse response
h_n = 0.05.^n - 0.25.^n;
% Convolution of unit step input x[n] and unit-pulse response h[n]
Y = conv(x_n,h_n);
figure(1);
stem(Y);

回答 (1 件)

Star Strider
Star Strider 2022 年 6 月 18 日
The easiest way is to just use xlim
syms t;
n = 0:20;
N = 21;
% piecewise of x1 and x2 for unit pulse
x_n = [1, zeros(1,20)];
% discrete time unit pulse response
h_n = 0.05.^n - 0.25.^n;
% Convolution of unit step input x[n] and unit-pulse response h[n]
Y = conv(x_n,h_n);
figure(1);
stem(Y);
xlim([min(n) max(n)])
.
  2 件のコメント
Anthony Walden
Anthony Walden 2022 年 6 月 18 日
Thank you for the help.
Star Strider
Star Strider 2022 年 6 月 18 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by