Effacer les filtres
Effacer les filtres

How to graph a moving plot while keeping another one static

4 vues (au cours des 30 derniers jours)
David Bustamante
David Bustamante le 19 Avr 2020
Commenté : M S Zobaer le 14 Mar 2022
I have to write some code to graphically demonstrate the process of convolution. So far I managed create a shifting square wave that moves from left to right. However whenever I try to add a static square wave and do hold on, the same graph is written over and over again. I understand explaining this through words might be a little confusing so I'll just post screenshots of what I currently have and what I want to achieve as well as my code.
Current output:
Expected Output:
x = linspace(-5, 5, 1000);
ft = rect(x,3);
gt = rect(x,2);
pulse2 = [0 ones(1,200) 0];
figure
ax_1 = subplot(3,1,1);
plot(x,ft)
axis([min(x) max(x) 0 1.5])
title('f(t)')
ax_2 = subplot(3,1,2);
p = plot(x,ft);
hold(ax_2,'on')
title('Graphical Convolution')
for k = 1:numel(x)-numel(pulse2)
plot(x(k:k+numel(pulse2)-1), pulse2)
axis([min(x) max(x) 0 1.5])
drawnow
end
hold(ax_2,'off')
  1 commentaire
M S Zobaer
M S Zobaer le 14 Mar 2022
how to get "Symbolic Math Toolbox" for free?
thanks

Connectez-vous pour commenter.

Réponses (1)

Devineni Aslesha
Devineni Aslesha le 22 Avr 2020
The graph overwriting can be avoided by updating the property 'XData' of the 'plot' function as follows.
pp = plot(x(1:1+numel(pulse2)-1), pulse2);
for k = 1:numel(x)-numel(pulse2)
pp.XData = (x(k:k+numel(pulse2)-1));
axis([min(x) max(x) 0 1.5])
drawnow
end

Catégories

En savoir plus sur 2-D and 3-D Plots 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