draw two 3D curve but can't hold them in one figure

조회 수: 1 (최근 30일)
Gary
Gary 2014년 8월 20일
댓글: Image Analyst 2014년 8월 20일
the first curve is a solution of a differential equation
function dy=eq3(t,y)
dy=zeros(3,1);
dy(1)=-680*(y(1)-100000)/sqrt((y(1)-100000)^2+(y(2)-340*t)^2+(y(3)-10000)^2);
dy(2)=-680*(y(2)-340*t)/sqrt((y(1)-100000)^2+(y(2)-340*t)^2+(y(3)-10000)^2);
dy(3)=-680*(y(3)-10000)/sqrt((y(1)-100000)^2+(y(2)-340*t)^2+(y(3)-10000)^2);
end
and the second one is a line in a 3Dspace
[t,y]=ode45('eq3',[0:0.01:202],[0,0,0]);
plot3(y(:,1),y(:,2),y(:,3))
grid on
hold on
T=0:0.5:200;
X=100000;
Y=340*T;
Z=10000;
plot3(X,Y,Z,'r')
xlabel('x轴')
ylabel('y轴')
zlabel('z轴')
but they don't show up together

답변 (1개)

Aniruddha Katre
Aniruddha Katre 2014년 8월 20일
The reason why the second plot does not show up is because the variables "X" and "Z" are both scalars while "Y" is a vector. You can just convert "X" and "Z" to vectors of the same dimensions as "Y" and the plot should work. Assuming you want to keep "X" and "Z" constant, you can convert them to vectors in the following manner:
X=100000*ones(length(T),1);
Z=10000*ones(length(T),1);
  댓글 수: 2
Gary
Gary 2014년 8월 20일
thx a lot
Image Analyst
Image Analyst 2014년 8월 20일
You can "thank" him by officially "Accepting" his answer. It will give him reputation points.

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

카테고리

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