3D plot rotate

21 vues (au cours des 30 derniers jours)
Aditya Rallapalli
Aditya Rallapalli le 16 Avr 2020
Modifié(e) : Star Strider le 16 Avr 2020
Hi all,
I have a 3D surf plotted in fig. 1 with axis X, Z and Y
Figure 1
I want to rotate the figure to get something like shown in fig.2
Figure 2
PS: Figure 2 is from book, I am just trying to generate similar figure using matlab. Both are same it's just about plotting in such a way that Y is in place of Z
  2 commentaires
Tommy
Tommy le 16 Avr 2020
Can you provide the code you used to generate the plot?
Aditya Rallapalli
Aditya Rallapalli le 16 Avr 2020
>> x = [0:0.01:1];
z = [0:0.01:1];
>> for i = 1:length(x)
for j = 1:length(z)
y1(i,j) = -sqrt(x(i) * z(j));
end
end
for i = 1:length(x)
for j = 1:length(z)
y2(i,j) = sqrt(x(i) * z(j));
end
end
surf(x,z,y1);hold on;
surf(x,z,y2)

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 16 Avr 2020
Modifié(e) : Star Strider le 16 Avr 2020
Use the rotate function.
EDIT — (16 Apr 2020 at 13:35)
Using your posted code and rotate:
x = [0:0.01:1];
z = [0:0.01:1];
for i = 1:length(x)
for j = 1:length(z)
y1(i,j) = -sqrt(x(i) * z(j));
end
end
for i = 1:length(x)
for j = 1:length(z)
y2(i,j) = sqrt(x(i) * z(j));
end
end
h(1) = surf(x,z,y1);
hold on
h(2) = surf(x,z,y2);
hold off
rotate(h, [1 0 0], 90)
produces:
If you want only the grids without the patch colours, add:
set(h, 'FaceColor','none')
to produce:
.

Plus de réponses (1)

Ameer Hamza
Ameer Hamza le 16 Avr 2020
Modifié(e) : Ameer Hamza le 16 Avr 2020
Try this. Correct the vector order for y and z-axis.
x = 0:0.01:1;
z = 0:0.01:1;
[X,Z] = meshgrid(x,z);
y1 = zeros(size(X));
for i = 1:length(x)
for j = 1:length(z)
y1(i,j) = -sqrt(x(i) * z(j));
end
end
y2 = zeros(size(X));
for i = 1:length(x)
for j = 1:length(z)
y2(i,j) = sqrt(x(i) * z(j));
end
end
surf(X,y1,Z);hold on;
surf(X,y2,Z)

Catégories

En savoir plus sur Line 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!

Translated by