How to show two figures of dynamic plots next to each other?

34 views (last 30 days)
Dear all,
I have two for-loops. Each loop generates a data which I am plotting (inside the loop) so as I can see the plot dynamically changing. Right now I process one plot which will open in one figure and once it is finished I close it and go to the next for-loop and see the second dynamic plot.
I want to be able to see these two dynamic plots at the same time. I tried to use subplot(2,1,1) in the first for-loop and subplot(2,2,1) in the second for-loop but things are not working well.
Is there someway to do it correctly?
Any help will be appreciated.
Meshoo

Accepted Answer

Thorsten
Thorsten on 8 Oct 2014
Use drawnow, pause, and specify the axis as in the following example
for i = 1:2
subplot(1,2,1)
axis([0 20 0 20])
plot(i, i, '.')
drawnow
hold on
subplot(1,2,2)
axis([0 20 0 400])
plot(i, i^2, 'o')
drawnow
hold on
pause(0.1)
end
  3 Comments
Felipe
Felipe on 4 Dec 2014
Hi Meshooo,
Which modifications did you use to make it work? I'm trying to plot two motions at the same time, but because of the first drawnow, the second one does not plot at the same time. Could you help me?
Thanks, -Felipe
Meshooo
Meshooo on 5 Dec 2014
Sure, try to run this code
for K = 1:200
A1 =sort(rand(K,1))*2*pi;
B1 =sort(rand(K,1))*2*pi;
subplot(1,2,1)
grid on
plot(A1, 'r', 'linewidth',2);
drawnow
hold on
subplot(1,2,2)
plot(B1, 'b', 'linewidth',2);
grid on
drawnow
pause(0.01);
end
I hope it's what you want.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!