Defining the limits for discrete time sequence on x axis using stem command

2 ビュー (過去 30 日間)
altaf ahmed
altaf ahmed 2019 年 10 月 19 日
回答済み: Star Strider 2019 年 10 月 20 日
In this sample program, I need to define the x axis as integers only rather than fractions.
x=[-2 1 -1 2]
nx=-1:2
h=[0 1 2]
nh=0:2
subplot(311)
stem(nx,x,'k')
xlabel('n')
ylabel('x(n)')
title('Input sequence x(n)')
subplot(312)
stem(nh,h,'k')
xlabel('n')
ylabel('h(n)')
title('Impulse Response h(n)')
  2 件のコメント
Daniel M
Daniel M 2019 年 10 月 20 日
What is the question
altaf ahmed
altaf ahmed 2019 年 10 月 20 日
Question: in the plots, the horizontal axis are needed to be integers only. Somehow they are coming in fractions. Is there a way to define this in stem command or plot command.

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

採用された回答

Star Strider
Star Strider 2019 年 10 月 20 日
Add these lines to each subplot:
xt = get(gca, 'XTick');
set(gca, 'XTick',min(xt):max(xt))
so the revised code is now:
x=[-2 1 -1 2]
nx=-1:2
h=[0 1 2]
nh=0:2
subplot(311)
stem(nx,x,'k')
xt = get(gca, 'XTick');
set(gca, 'XTick',min(xt):max(xt))
xlabel('n')
ylabel('x(n)')
title('Input sequence x(n)')
subplot(312)
stem(nh,h,'k')
xt = get(gca, 'XTick');
set(gca, 'XTick',min(xt):max(xt))
xlabel('n')
ylabel('h(n)')
title('Impulse Response h(n)')
Note that here, the minimum and maximum x-tick values are integers. If they are not in other plots, you will have to change the added lines appropriately to make them integer values, for example:
set(gca, 'XTick',floor(min(xt)):ceil(max(xt)))
Experiment to get the result you want.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by