How to make a stem graph to display less points?

7 vues (au cours des 30 derniers jours)
Sergei
Sergei le 4 Déc 2024
Modifié(e) : Sergei le 6 Déc 2024
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 commentaires
Sergei
Sergei le 4 Déc 2024
Modifié(e) : Sergei le 4 Déc 2024
Though, if I do not open the figure in full-screen, there is no problem.
Walter Roberson
Walter Roberson le 4 Déc 2024
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.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 4 Déc 2024
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 commentaire
Sergei
Sergei le 6 Déc 2024
Modifié(e) : Sergei le 6 Déc 2024
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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by