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 Center および File Exchange2-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