作一个3D函数图
x=-10:0.1:10;
y=x;
[X,Y]=meshgrid(x,y);%生成坐标网格分量矩阵X和Y
figure,mesh(X,Y,sin(X+Y));%运行结果如下图1
figure,surf(X,Y,sin(X+Y)),shadinginterp;%运行结果如下图2
![matlab <wbr>每日学习 <wbr>3D作图 <wbr> <wbr>surf <wbr>mesh <wbr>meshgrid函数 matlab <wbr>每日学习 <wbr>3D作图 <wbr> <wbr>surf <wbr>mesh <wbr>meshgrid函数](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
图1
![matlab <wbr>每日学习 <wbr>3D作图 <wbr> <wbr>surf <wbr>mesh <wbr>meshgrid函数 matlab <wbr>每日学习 <wbr>3D作图 <wbr> <wbr>surf <wbr>mesh <wbr>meshgrid函数](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
图2
用一种更简单的方式
[X,Y]=meshgrid(-10:.1:10);
mesh(X,Y,sin(X.*Y));
MESHGRID X and Y arrays for3-D plots.
[X,Y] =MESHGRID(x,y) transforms the domain specified by vectors
x and y intoarrays X and Y that can be used for the evaluation
of functionsof two variables and 3-D surface plots.
The rows ofthe output array X are copies of the vector x and
the columnsof the output array Y are copies of the vector y.
[X,Y] =MESHGRID(x) is an abbreviation for [X,Y] = MESHGRID(x,x).
[X,Y,Z] =MESHGRID(x,y,z) produces 3-D arrays that can be used to
evaluatefunctions of three variables and 3-D volumetric plots.
For example,to evaluate the function x*exp(-x^2-y^2) overthe
range -2 < x <2, -2 < y <2,
[X,Y] = meshgrid(-2:.2:2, -2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);
surf(X,Y,Z)
MESHGRID islike NDGRID except that the order of the first two input
and outputarguments are switched (i.e., [X,Y,Z] = MESHGRID(x,y,z)
produces thesame result as [Y,X,Z] = NDGRID(y,x,z)). Becauseof
this,MESHGRID is better suited to problems in cartesian space,
while NDGRIDis better suited to N-D problems that aren't spatially
based. MESHGRID is also limited to 2-D or3-D.
Classsupport for inputs X,Y,Z:
float: double, single