📅  最后修改于: 2021-01-07 02:51:40             🧑  作者: Mango
MATLAB还包含各种三维图,这些图对于显示某些类型的数据很有用。通常,三维图有助于显示两种类型的数据:
为了获得z,首先,我们必须使用meshgrid函数创建一组(x,y)点。
[X,Y] = meshgrid(-1:.2:1);
此处,函数meshgrid中的参数是一个向量,使用冒号运算符创建(开始:步骤:结束)
meshgrid函数最多可以包含三个向量参数,并根据参数中向量的坐标返回二维坐标。
Grid coordinates set (matrix) | Function | Vector coordinates | Grid length |
---|---|---|---|
[X,Y], X & Y are matrices, where each row is a copy of x, and each column is a copy of y respectively. |
=meshgrid(x,y), returns 2-D grid coordinates based on x & y | Coordinates of Vector x and y | No. of rows in X & Y = length(y), No. of columns in X & Y = length(x) |
[X,Y], X & Y are matrices, where each row and column is a copy of x. |
=meshgrid(x), equivalent to meshgrid(x,x), and returns square 2-D grid coordinates based on x | Coordinates of Vector x | Grid size = length(x) by length(x) |
[X, Y, Z], X have coordinates of x, Y have coordinates of y, and Z have coordinates of z | =meshgrid(x,y,z), returns 3-D grid coordinates based on vectors x, y, & z | Coordinates of Vectors x, y, and z. | Grid size = length(y) by length(x) by length(z) |
[X,Y,Z], All have same coordinates of x |
=meshgrid(x), is same as meshgrid(x,y,z) in the form of meshgrid(x,x,x) | Coordinates of Vector x | 3-D grid size = lenght(x) by length(x) by length(x) |
现在评估Z以创建3-D图:
Z = X. * exp(-X。^ 2-Y. ^ 2); %点。运算符用于执行逐元素计算。
现在,我们将使用函数surf(X,Y,Z)创建一个3-D表面图。
通过输入surf函数,它将生成3-D表面图。