matlab中meshgrid函数的⽤法
meshgrid 的使⽤⽅法:
[X,Y] = meshgrid(x,y) 将向量x和y定义的区域转换成矩阵X和Y,这两个矩阵可以⽤来表⽰mesh和surf的三维空间点以及两个变量的赋值。其中矩阵X的⾏向量是向量x的简单复制,⽽矩阵Y的列向量是向量y的简单复制。
Generate X and Y matrices for three-dimensional plots
Syntax:
[X,Y] = meshgrid(x,y)
[X,Y] = meshgrid(x)
[X,Y,Z] = meshgrid(x,y,z)
Description:
[X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can
be used to evaluate functions of two variables and three-dimensional mesh/surface plots. The rows of the output array X are copies of the vector x; columns of the output array Y are copies of the vector y.
[X,Y] = meshgrid(x) is the same as [X,Y] = meshgrid(x,x).
[X,Y,Z] = meshgrid(x,y,z) produces three-dimensional arrays used to evaluate functions of three variables and three-dimensional volumetric plots.
Remarks:
The meshgrid function is similar to ndgrid except that the order of the first two input and output arguments is switched. That is, the statement [X,Y,Z] = meshgrid(x,y,z)
produces the same result as [Y,X,Z] = ndgrid(y,x,z)
Because of this, meshgrid is better suited to problems in two- or three-dimensional Cartesian space, while ndgrid is better suited to multidimensional problems that aren't spatially based.
meshgrid is limited to two- or three-dimensional Cartesian space.
From:⽹易博客
详细解释:help meshgrid
meshgrid⽤于从数组a和b产⽣⽹格。⽣成的⽹格矩阵A和B⼤⼩是相同的。它也可以是更⾼维的。
[A,B]=Meshgrid(a,b)
⽣成size(b)Xsize(a)⼤⼩的矩阵A和B。它相当于a从⼀⾏重复增加到size(b)⾏,把b转置成⼀列再重复增加到size(a)列。因此命令等效于:A=ones(size(b))*a;
B=b'*ones(size(a))
如下所⽰:
>> a=[1:2]
a =
1    2
>> b=[3:5]
b =
3    4    5
>> [A,B]=meshgrid(a,b)
A =
1    2
1    2
1    2
B =
3    3
4    4
5    5
>> [B,A]=meshgrid(b,a)
B =
3    4    5
3    4    5
A =
rows函数的使用方法及实例
1    1    1
2    2    2

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。