How do you plot average of 3 arrays over time?
이전 댓글 표시
Hello, I 'm still new to Matlab so any help would be appreciated.
I've been able to plot a propogation for the three body problem. I would like to include a plot for how the center of mass of the three bodies changes over time, too. In this problem the three masses are equal, so the center of mass would be the average of their positions at a given time.
Right now I have it setup that each of the positions x,y and z have their own arrays 5000 x 3. Each column, 1-3, corresponds to one of the three bodies and the rows is that x,y, or z positions as time changes.
My question is how can I take the average of each position, for the center of mass, and include it in the plot?
Thanks!
Example of my X array
0 1 2
0 1.00100000000000 2
1.25000000000000e-06 1.00200000000000 1.99999875000000
3.74800000798251e-06 1.00300000399998 1.99999624800001
etc.
How I'm plotting:
figure()
view([45 45 45 ])
hold on
plot3(x(:,1),y(:,1),z(:,1))
plot3(x(1,1),y(1,1),z(1,1),'r*')
plot3( x(:,2) ,y(:,2),z(:,2))
plot3(x(2,2),y(2,2),z(2,2),'r*')
plot3( x(:,3) ,y(:,3),z(:,3))
plot3(x(3,3),y(3,3),z(3,3),'r*')
xlabel('x')
ylabel('y')
zlabel('z')
legend('B1','B1 start','B2','B2 start','B3','B3 start')
grid on
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!