Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Gary
Gary le 20 Août 2014
Commenté : Image Analyst le 20 Août 2014
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

Réponses (1)

Aniruddha Katre
Aniruddha Katre le 20 Août 2014
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 commentaires
Gary
Gary le 20 Août 2014
thx a lot
Image Analyst
Image Analyst le 20 Août 2014
You can "thank" him by officially "Accepting" his answer. It will give him reputation points.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by