📅  最后修改于: 2023-12-03 14:44:10.962000             🧑  作者: Mango
The waterfall()
function in MATLAB allows for the creation of a type of 3D plot called a waterfall plot. This function takes in a matrix of z-values, and plots them in a way that creates multiple 2D line plots that appear to drop down from a single 3D surface.
waterfall(x,y,z)
x
and y
: vectors representing the x and y coordinates of the data pointsz
: a matrix of the same size as length(y)
-by-length(x)
containing the z-values to plotHere is an example of how to use the waterfall()
function:
% Define x and y vectors
x = 1:10;
y = 1:10;
% Create a meshgrid from x and y
[X,Y] = meshgrid(x,y);
% Define a z function to plot
Z = sin(sqrt(X.^2 + Y.^2)) ./ (sqrt(X.^2 + Y.^2));
% Create a 3D waterfall plot
waterfall(X,Y,Z)
% Add labels and adjust view
xlabel('X Axis')
ylabel('Y Axis')
zlabel('Z Axis')
title('Waterfall Plot')
view([-120 30])
This will generate a 3D waterfall()
plot of the function Z = sin(sqrt(X.^2 + Y.^2)) ./ (sqrt(X.^2 + Y.^2))
, with the x and y axes ranging from 1 to 10. The resulting plot should look similar to the following:
There are many customization options available for the waterfall()
function, including setting the colors of each line plot, adjusting the transparency of the surface, adding grid lines, and more. For more information on these options, check out the MATLAB documentation for waterfall()
.