How to make a stem graph to display less points?

24 views (last 30 days)
Sergei
Sergei on 4 Dec 2024 at 0:38
Edited: Sergei on 6 Dec 2024 at 14:58
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 Comments
Sergei
Sergei on 4 Dec 2024 at 0:41
Edited: Sergei on 4 Dec 2024 at 0:41
Though, if I do not open the figure in full-screen, there is no problem.
Walter Roberson
Walter Roberson on 4 Dec 2024 at 0:42
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.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 4 Dec 2024 at 1:42
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 Comment
Sergei
Sergei on 6 Dec 2024 at 14:56
Edited: Sergei on 6 Dec 2024 at 14:58
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!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!