MATLAB: How to animate two plots at the same time

animationcomet3getframe

Hi everyone!
recently I've been making an orbit propagator where I plot an orbit around the Earth by plotting 2-body problem using ode45 and animate the orbit around the Earth.. but what happens is the rotation of Earth will be animated first and then the animation of the orbit begins after the Earth stops… is there any way I can make both happen at the same time?
the code:
Map = imread('earthmap.jpg');
Re = 6378; %km
[X, Y, Z]= sphere
Earth = surf(Re*X, Re*Y, -Re*Z)
set(Earth,'FaceColor','texturemap','Cdata',Map,'EdgeColor','none')
set(gcf,'Color','k')
set (gca,'Color','k')
axis equal
rotE = 360/24; %deg per hour
%Earth rotating around Z axis.
Ndays = Period/86400; %number of hours
tr = Ndays*24; %one day
for ir = 1:1:tr+1 %since time starts from 1 not 0
rotate(Earth,[0 0 1],rotE);
Anim = getframe(gca);
end
hold on
comet3(xv,yv,zv) %xv yv zv are the values I get from solving the 2-body problem which I didn't include here

Best Answer

Put this line:
comet3(xv,yv,zv) %xv yv zv are the values I get from solving the 2-body problem which I didn't include here
into a loop as shown below:
n = length(xv) ;
for i = 1:n
plot3(xv(1:i),yv(1:i),zv(1:i)) ;
drawnow
end
If you are looking to inclide comet along with another animation.