3-D Visualization | ![]() ![]() |
The 3-D analog of the plot
function is plot3
. If x
, y
, and z
are three vectors of the same length,
plot3(x,y,z)
generates a line in 3-D through the points whose coordinates are the elements of x
, y
, and z
and then produces a 2-D projection of that line on the screen. For example, these statements produce a helix.
t = 0:pi/50:10*pi; plot3(sin(t),cos(t),t) axis square; grid on
Plotting Matrix Data
If the arguments to plot3
are matrices of the same size, MATLAB plots lines obtained from the columns of X
, Y
, and Z
. For example,
[X,Y] = meshgrid([-2:0.1:2]); Z = X.*exp(-X.^2-Y.^2); plot3(X,Y,Z) grid on
Notice how MATLAB cycles through line colors.
![]() | A Typical 3-D Graph | Representing a Matrix As a Surface | ![]() |