How can i draw a simultaneous animated plot?

1 次查看(过去 30 天)
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

采纳的回答

Giuseppe Cazzetta
Giuseppe Cazzetta 2015-11-6
thanks a lot Mike for the answer i made it by using
set(h,'visible','off')
set(h,'visible','on');
where 'h' is the plot variable
%defining variables
np=length(xT);
x=flip(xT);
y=yT;
z=zT;
h=figure();
set(h,'visible','off'); %ths prevent figure to show data
subplot (1,2,1)
% starting plotting first point plot1
plot3(x(1),y(1),z(1))
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
zlim([min(z) max(z)]);
grid
view([180 90])
hold on
%starting plotting first point plot2
subplot (1,2,2)
plot3(x(1),y(1),z(1))
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
zlim([min(z) max(z)]);
grid
view([180 0])
hold on
%starting add the others point
for i=2:np-1
subplot (1,2,1)
plot3(x(i:i+1),y(i:i+1),z(i:i+1),'-r','linewidth',2)
plot3(x(i+1),y(i+1),z(i+1),'o','markerfacecolor','r')
plot3([x(i+1) x(i+1)],[y(i+1) y(i+1)],[0 z(i+1)],'b')
subplot (1,2,2)
plot3(x(i:i+1),y(i:i+1),z(i:i+1),'-r','linewidth',2)
plot3(x(i+1),y(i+1),z(i+1),'o','markerfacecolor','r')
plot3([x(i+1) x(i+1)],[y(i+1) y(i+1)],[0 z(i+1)],'b')
pause(sec+0.05) %just a pause to see data better
set(h,'visible','on') %this show all the data again
end
%%clear temporary variables
clear enable_plot_vertical enable_plot_dot_3d...
enable_plot_line_3d i np on off
  1 个评论
Thorsten
Thorsten 2015-11-6
Guiseppe, the idea is to accept the answer of Mike, not your own comment to the answer.

请先登录,再进行评论。

更多回答(1 个)

Mike Garrity
Mike Garrity 2015-11-3
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?

类别

Help CenterFile Exchange 中查找有关 2-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