Plot a 3d-plane in MATLAB??
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to plot a 3d-plane (x=0) in MATLAB, (-2<=y<=2) and limited by the line z=4-y^2. Here's my code :
y=linspace(-2,2,50);
z=4-y.^2;
[Y Z]=meshgrid(y,z);
X=0*Y+0*Z;
mesh(X,Y,Z);
axis tight;
Can you give me any hints???? thank you very much!!
2 commentaires
Walter Roberson
le 22 Mai 2014
Modifié(e) : Walter Roberson
le 22 Mai 2014
What is the difference between this question and http://www.mathworks.co.uk/matlabcentral/answers/130475-how-to-draw-a-graph-in-3d ?
When you say that the plane is to be limited by that z, and that you want to draw plot it, then what difference is there compared to plotting a single curved line in 3 space?
Réponse acceptée
Hugo
le 22 Mai 2014
This solution is based on patch
y=-2:.01:2;
z=4-y.^2;
numy=length(y);
% Constructing the vertices
V=zeros(numy,3);
for iy=1:numy,
V(iy,:)=[0,y(iy),z(iy)]; % Vertices in the parabola
V(iy+numy,:)=[0,y(iy),0]; % Vertices in the y axis
end
% Constructing faces
F=zeros(numy-1,4); for iy=1:numy-1, F(iy,:)=[iy,iy+1,iy+1+numy,iy+numy]; end
patch('Vertices',V,'Faces',F)
The plot may look like a line. You just need to rotate it and you will see the figure in 3D.
Hope this helps.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!