How to plot multiple functions on one graph>

조회 수: 4 (최근 30일)
DaHart
DaHart 2015년 4월 17일
댓글: DaHart 2015년 4월 17일
I need to plot the orbits of four different planets on the same graph in Matlab. The code below works for each plot individually, creating the orbit plot that I want. However, when I put all the codes together like I do below, I get a plot that looks like 4 straight lines going in random directions.
ro=[0,0,1.50e11];
vo=[0,2*pi*ro(3)/(365*24*60*60),0];
for n=1:730
delt_t=24*60*60
[r,v]= orbits3d(ro,vo,delt_t)
plot3(r(1),r(2),r(3), 'go')
hold on
ro=r
vo=v
end
ro=[0,0,2.28e11];
vo=[2*pi*ro(2)/(365*24*60*60*1.88),0,0];
for n=0:1:730*1.88
delt_t=24*60*60
[r,v]= orbits3d(ro,vo,delt_t)
plot3(r(1),r(2),r(3), 'ro')
hold on
ro=r
vo=v
end
ro=[0,0.58e11,0];
vo=[2*pi*ro(1)/(365*24*60*60*0.241),0,0];
for n=1:730*.241
delt_t=24*60*60
[r,v]= orbits3d(ro,vo,delt_t)
plot3(r(1),r(2),r(3), 'bo')
hold on
ro=r
vo=v
end
ro=[0,1.08e11,0];
vo=[0,0,2*pi*ro(3)/(365*24*60*60*0.615)];
for n=1:730*.615
delt_t=24*60*60
[r,v]= orbits3d(ro,vo,delt_t)
plot3(r(1),r(2),r(3), 'mo')
hold on
ro=r
vo=v
end
How can I make it so each orbit appears on the graph without affecting the other graphs?
Thanks

채택된 답변

James Tursa
James Tursa 2015년 4월 17일
편집: James Tursa 2015년 4월 17일
plot3 with hold on should have worked. That being said, looks like the last three cases have vo typos to me, since vo is all 0's in these cases. E.g., the 2nd case has
ro=[0,0,2.28e11];
vo=[2*pi*ro(2)/(365*24*60*60*1.88),0,0];
but ro(2) is 0, so vo(1) will be 0. Did you mean to use ro(3) in this case?
Same comment for all of the last three cases. As you have it, these cases are degenerate rectilinear orbits (i.e., straight lines) falling straight into the planet.
  댓글 수: 1
DaHart
DaHart 2015년 4월 17일
whoops, didn't notice that when I changed the placement of those values. This worked, thanks so much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Earth and Planetary Science에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by