clear all
for n=1:1
filename=strcat("D:\2021fall\applied_math\tri_body\mat-new\mat_threebody",num2str(n),".dat");
threebody=importdata(filename);
clc
T=900;
a=zeros(T,3);
b=zeros(T,3);
c=zeros(T,3);
for i=1:T
for j=1:3
a(i,j)=threebody(i,j);
b(i,j)=threebody(i,j+3);
c(i,j)=threebody(i,j+6);
end
end
fps=30;
filename2=strcat('mat_threebody',num2str(n),'.avi');
myvideo=VideoWriter(filename2);
myvideo.FrameRate=fps;
open(myvideo);
for i=1:T
for k=1:3
tm1=a(i,k);
tm2=b(i,k);
tm3=c(i,k);
A=[tm1,tm2,tm3];
xmax(k)=1.5*max(A);
xmaxk=max(xmax);
xmin(k)=1.5*min(A);
xmink=min(xmin);
end
plot3(a(i,1),a(i,2),a(i,3),'ro','MarkerFacecolor','r','MarkerSize',6)
hold on
plot3(b(i,1),b(i,2),b(i,3),'go','MarkerFacecolor','g','MarkerSize',6)
plot3(c(i,1),c(i,2),c(i,3),'ko','MarkerFacecolor','k','MarkerSize',6)
p=1;
plot3(a(p:i,1),a(p:i,2),a(p:i,3),'r-')
plot3(b(p:i,1),b(p:i,2),b(p:i,3),'g-')
plot3(c(p:i,1),c(p:i,2),c(p:i,3),'k-')
axis([xmink xmaxk xmink xmaxk xmink xmaxk]);
drawnow
view(2)
hold off
frame=getframe(gcf);
im=frame2im(frame);
writeVideo(myvideo,im);
end
close(myvideo);
end