How to make a stem graph to display less points?

3 ビュー (過去 30 日間)
Sergei
Sergei 2024 年 12 月 4 日
編集済み: Sergei 2024 年 12 月 6 日
Dear All,
The following code produces the following graphs.
Of course, I do not need the part of the second graph before the point -3. How to cut this part?
  2 件のコメント
Sergei
Sergei 2024 年 12 月 4 日
編集済み: Sergei 2024 年 12 月 4 日
Though, if I do not open the figure in full-screen, there is no problem.
Walter Roberson
Walter Roberson 2024 年 12 月 4 日
It is much better to post code as text instead of a picture of code. None of us have a version of MATLAB that is able to run code from pictures.

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

採用された回答

Image Analyst
Image Analyst 2024 年 12 月 4 日
Use axis
% Make t axis go from -3 to the maximum.
axis([-3, max(t)]);
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
  1 件のコメント
Sergei
Sergei 2024 年 12 月 6 日
編集済み: Sergei 2024 年 12 月 6 日
The revised code looks like this:
clear all; clc; close all;
%How much elements of x[n] we print (must be not even)
N = 11;
t = (-(N-1)/2:(N-1)/2);
x = zeros(1, N);
%Index of x[0] in x
zero = (N-1)/2+1;
x(zero-2) = 1; x(zero-1) = 2; x(zero) = 3; x(zero+1) = -1; x(zero+2) = 4; x(zero+3) = -2;
%(a)
figure; subplot(2, 5, 1);
stem(t, x, LineWidth=2); title('x[n]');xticks(min(t):max(t)); grid on; axis([min(t), max(t), -3, 5]);
subplot(2, 5, 2);
stem(t+2, x, LineWidth=2); title("x[n-2]"); axis([min(t+2), max(t+2), -3, 5]); xticks(min(t+2):max(t+2)); grid on;
What helped is writing "axis([min(t+2), max(t+2), -3, 5])" instead of "axis([min(t+2), max(t+2)])", because axis command takes 4, 6 or 8 valued vector as an input only
Still thank you, that you pointed at this command and helped me solving the problem!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by