tags: Matlab
ndgridFunction andmeshgridThe function is similar, but the former supports from 1 to n dimensions, while the latter is only limited to 2 and 3 dimensions. In 2D and 3D, the coordinate output of the two functions is the same. The difference lies in the shape of the output array. For grid vectors x1gv, x2gv, x3gv, the lengths are M, N, and P respectively.ndgrid(x1gv, x2gv)The function outputs an array of MXN, andmeshgrid(x1gv, x2gv)Output an N*M array, similarly,ndgrid(x1gv, x2gv, x3gv)The function outputs an array of M*N*P, andmeshgrid(x1gv, x2gv, x3gv)Output an array of N*M*P .
The following example illustrates
For example, the dimensions of x1gv, x2gv, and x3gv are 2, 3, and 4 respectively. After executing the two functions, a = ndgrid(x1gv,x2gv,x3gv), the dimensions of the output a is 2x3x4, and b = meshgrid(x1gv,x2gv,x3gv), the output dimension is 3x2x4.
The following explains the ndgrid() function in detail
[X1,X2,X3,...] = ndgrid(x1gv,x2gv,x3gv,...), copy the values of x1gv,x2gv,x3gv,... to generate a rectangular grid coordinate (X1,X2,X3,...). The element of the i-th dimension of the output array Xi is copied from the grid vector xigv. For example, the grid vector x1gv forms the rows of X1, the grid vector x2gv forms the columns of X2, and so on...
The above may be more convoluted, for a simple example,
among them,
x1gv = [1 1.1 1.2 1.3 1.4 1.4 1.5 1.6 1.7 1.8 1.8 1.9 2], dimension is 1*11, length is 11, x2gv = [4 4.2 4.4 4.6 4.8 5], dimension The number is 1*6 and the length is 6, then, the rows of the output a are copied from the elements of x1gv, and the columns of the output b are also copied from the elements of x2gv.
The output result is as follows: As mentioned above, the dimension of the output array should be 11*6. Compare the contents of a and b with x1gv and x2gv, and you can understand the above Mouth place.
Finally, the dimension of the output array is determined by the number of output variables, which is determined byndgrid(……)Determined by the number of output lists on the right side of the function. This sentence means that if the number of outputs is 1, then the dimension is N*1, and N is the length of the grid vector, if the number of outputs is 2, then the dimension of each is N*N.
gives a dazzling drawing method
The above explanation may not be very clear, you can refer to the help file of matlab for details
Attach the link:http://cn.mathworks.com/help/matlab/ref/ndgrid.html
Matlab function Meshgrid's role:...
1、[x,y]=meshgrid(1:n,1:m); The data of the network sample point is generated, the number of lines of X, Y is equal to M, the column number is equal to N. 2、MeshGrid is used to generate grids from arra...
Meshgrid is a statement used to construct a two-dimensional or three-dimensional grid that uses [X,Y] = meshgrid(x,y) or [X,Y,Z] = meshgrid(x,y,z) X, Y represents a "length" of a certain dim...
Recently I saw a very clear article explaining the mgrid () and meshgrid () functions, which is collected and reproduced here. The original link: First, the meshgrid function The meshgrid funct...
One, meshgrid function The meshgrid function is usually used for vectorization of data. It is suitable for generating grid data and can accept two one-dimensional arrays to generate two two-dimensiona...
Function form [C,R] =meshgrid(c, r) Preliminary explanation The first thing to be clear is that the parameters c and r are both row vectors. This function transforms the domain specified by the row ve...
The meshgrid function is used to generate a grid matrix, which can be two-dimensional or three-dimensional. For generating a two-dimensional grid, the usage is: [xy]=meshgrid(ab);% a and b are one-dim...
It can be understood that the meshgrid function draws a grid on a plane with points on two coordinate axes. Usage: Take [X,Y]=meshgrid(x,y) as an example to introduce this function. [X,Y] = meshgrid(x...
The meshgrid function can be used to generate the index of a two-dimensional matrix. The tile function can copy the list in a certain dimension. It is assumed to be two-dimensional: &nbs...
[Matlab] Three-dimensional surface (rectangular grid—meshgrid) Two-dimensional curve: First find x, find the corresponding y, and draw the point. Run screenshot For 3D surfaces: First find (x, y...