How can i draw a simultaneous animated plot?
Show older comments
Hello all, this is the first time i write here. I made this plotting and basically is the same plot but in different point of view. I would like to start the "two cycle for" simultaneously, or at least plotting the result simultaneously. I saw there is another question like this but i can't understand the answer.
%%defining variables
np=length(xT);
x=flip(xT);
y=yT;
z=zT;
%%a kind of option menú
on=1;
off=0;
enable_plot_dot_3d=off;
enable_plot_line_3d=on;
enable_plot_vertical=on;
subplot (1,2,1)
%%starting plotting first point
plot3(x(1),y(1),z(1))
view([180 90]) %set azimuth and elevation of plot
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
zlim([min(z) max(z)]);
grid
hold on
%%starting add the others point according of menú
for i=2:np-1
% line (i make a mistake with variable name)
if(enable_plot_dot_3d) %un po inutile per me
plot3(x(i:i+1),y(i:i+1),z(i:i+1),'-r','linewidth',2)
end
% dots
if(enable_plot_line_3d)
plot3(x(i+1),y(i+1),z(i+1),'o','markerfacecolor','r')
end
% height marker
if(enable_plot_vertical)
plot3([x(i+1) x(i+1)],[y(i+1) y(i+1)],[0 z(i+1)],'b')
end
% plot speedy
pause(sec+0.05)
end
subplot (1,2,2)
%%starting plotting first point
plot3(x(1),y(1),z(1))
view([180 0]) %set azimuth and elevation of plot
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
zlim([min(z) max(z)]);
grid
hold on
%%starting add the others point according of menú
for i=2:np-1
% line (i make a mistake with variable name)
if(enable_plot_dot_3d) %un po inutile per me
plot3(x(i:i+1),y(i:i+1),z(i:i+1),'-r','linewidth',2)
end
% dots
if(enable_plot_line_3d)
plot3(x(i+1),y(i+1),z(i+1),'o','markerfacecolor','r')
end
% height marker
if(enable_plot_vertical)
plot3([x(i+1) x(i+1)],[y(i+1) y(i+1)],[0 z(i+1)],'b')
end
% plot speedy
pause(sec+0.05)
end
%%clear temporary variables
clear enable_plot_vertical enable_plot_dot_3d...
enable_plot_line_3d i np on off
Accepted Answer
More Answers (1)
Mike Garrity
on 3 Nov 2015
Basically you just want one loop with both plotting commands in it. The tricky part of that is that you're currently depending on GCA when you call plot3. If you want to combine them into a single loop, you're probably going to need to be explicit about which axes each plot goes in. That would look something like this:
%%Create 1st axes
a1 = subplot (1,2,1)
%%starting plotting first point
plot3(x(1),y(1),z(1))
view([180 90]) %set azimuth and elevation of plot
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
zlim([min(z) max(z)]);
grid
hold on
%%Create 2nd axes
a2 = subplot (1,2,2)
%%starting plotting first point
plot3(x(1),y(1),z(1))
view([180 0]) %set azimuth and elevation of plot
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
zlim([min(z) max(z)]);
grid
hold on
%%starting add the others point according of menú
for i=2:np-1
% update 1st axes
% line
if(enable_plot_dot_3d) %un po inutile per me
plot3(a1,x(i:i+1),y(i:i+1),z(i:i+1),'-r','linewidth',2)
end
% dots
if(enable_plot_line_3d)
plot3(a1,x(i+1),y(i+1),z(i+1),'o','markerfacecolor','r')
end
% height marker
if(enable_plot_vertical)
plot3(a1,[x(i+1) x(i+1)],[y(i+1) y(i+1)],[0 z(i+1)],'b')
end
% update 2nd axes
% line
if(enable_plot_dot_3d) %un po inutile per me
plot3(a2,x(i:i+1),y(i:i+1),z(i:i+1),'-r','linewidth',2)
end
% dots
if(enable_plot_line_3d)
plot3(a2,x(i+1),y(i+1),z(i+1),'o','markerfacecolor','r')
end
% height marker
if(enable_plot_vertical)
plot3(a2,[x(i+1) x(i+1)],[y(i+1) y(i+1)],[0 z(i+1)],'b')
end
% plot speedy
pause(sec+0.05)
end
The important bit here is saving the return values from the 2 calls to subplot (a1 and a2), and then using those as the first arguments in the calls to plot3. That way you can be managing multiple plots at the same time in your loop.
Does that make sense?
Categories
Find more on 2-D and 3-D Plots 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!