# How to plot an array in 3D?

10 visualizaciones (últimos 30 días)
John el 1 de Feb. de 2024
Comentada: Star Strider el 1 de Feb. de 2024
A 2D array S, plot(S) showing below, how to plot it in a 3D looking (plot3 did not work)?
Thank you for help!
##### 3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
John el 1 de Feb. de 2024
"Did you provide 3 arrays (of the compatible size) as input? "
There is no 3 arrays. How to do it?
Dyuman Joshi el 1 de Feb. de 2024
Then I suppose you want to see the same graph obtained in 3-dimensional view. For that, use view.
If that is not what you want, please specify.

Iniciar sesión para comentar.

### Respuestas (2)

Star Strider el 1 de Feb. de 2024
view(-30,30)
after creating the plot.
Use whatever azimuth (first eargument in degrees) and elevation (second argument in degrees) that you want to show it from the direction you want.
##### 2 comentariosMostrar NingunoOcultar Ninguno
John el 1 de Feb. de 2024
Thank you! But I would like to plot it each line on a separate axis number and all lines on the z-axis, like a 3D plot, but based on this 2D array.
Star Strider el 1 de Feb. de 2024
I assume that you want the lines separated by constant z-axis values.
x = linspace(0, 275, 275);
y = sin((1:10).'*2*pi*x) + (0:9).'*0.5;
figure
plot(x, y)
xlabel('x')
ylabel('y')
z = ones(size(y)) + (0:9).';
figure
plot3(x, y, z)
grid on
xlabel('x')
ylabel('y')
zlabel('z')
It would help to have your data.
.

Iniciar sesión para comentar.

Voss el 1 de Feb. de 2024
"I would like to plot it each line on a separate axis number and all lines on the z-axis, like a 3D plot, but based on this 2D array"
Something like this?
t = (1:200).';
S = [cosd(t) sind(t) 1./t exp(-t/100)];
% 3-D plot
figure
[m,n] = size(S);
[X,Z] = ndgrid(1:m,1:n);
plot3(X,S,Z)
xlabel('x')
ylabel('y')
zlabel('z')
box on
grid on
% (copy the axes to a new figure, for demonstration purposes only)
copyobj(gca(),figure())
% note that, when viewed from above, the 3-D plot looks the same as the 2-D plot
view(2) % 2-D (X,Y) view
% 2-D plot for comparison:
figure
plot(S);
xlabel('x')
ylabel('y')
zlabel('z')
box on
grid on
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Line Plots en Help Center y File Exchange.

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by