In addition to the plot3 function mentioned earlier, there are also the following functions.
1. Draw a 3D grid map
1 mesh function
eg: drawing function
%1 三维网格图mesh函数
%绘制函数z=x^2+y^2+6
x=-4:.2:4;
y=x;
[X,Y]=meshgrid(x,y);%生成网格矩阵
Z=X.^2+Y.^2+6;
mesh(X,Y,Z)
2. Draw a three-dimensional grid map and add the bottom projection peaks function
eg:
%绘制三维网格图并且在下面绘制投影peaks函数
[X,Y]=meshgrid(-3:.125:3);
Z=peaks(X,Y);
meshc(X,Y,Z);
axis([-3 3 -3 3 -10 5]) %x y z 坐标轴范围
2. Draw a three-dimensional display map and add the bottom projection surf function
eg :
%绘制三维曲面图并且在下面绘制投影surf函数
[X,Y,Z]=peaks(30);
surfc(X,Y,Z);
colormap spring %设置颜色,可以换成hsv、summer等试一试
axis([-3 3 -3 3 -10 5]) %x y z 坐标轴范围
%peaks是一个函数,其中有2个变量。由平移和放缩高斯分布函数获得。
% 这里输入n(=30)是说输出30*30的矩阵
%Z = peaks(n) %生成n×n的矩阵;Z = peaks(X,Y) %计算给定x和y(必须是相同大小)的峰值,并返回一个大小相同的矩阵。
Note:
peaks is a function with 2 variables. Obtained by shifting and scaling a Gaussian distribution function.
Entering n (=30) here means outputting a matrix of 30*30
Z = peaks(n) % generate a matrix of n×n; Z = peaks(X,Y) % calculate the peaks of the given x and y (must be the same size), and return a matrix of the same size.
The peaks function can be directly input and viewed in matlab: