How to make a stem graph to display less points?

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

Community Treasure Hunt

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

Start Hunting!

Translated by