How to graph a moving plot while keeping another one static

3 ビュー (過去 30 日間)
David Bustamante
David Bustamante 2020 年 4 月 19 日
コメント済み: M S Zobaer 2022 年 3 月 14 日
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 件のコメント
M S Zobaer
M S Zobaer 2022 年 3 月 14 日
how to get "Symbolic Math Toolbox" for free?
thanks

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

回答 (1 件)

Devineni Aslesha
Devineni Aslesha 2020 年 4 月 22 日
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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by