Showing posts with label meshgrid matlab Function. Show all posts
Showing posts with label meshgrid matlab Function. Show all posts

Sunday, November 29, 2020

, ,

meshgrid MATLAB Function With It's example surface plot of a function.

meshgrid matlab Function:-

Helps to generate X and Y matrices for three-dimensional plots.

Syntax For meshgrid: -

[X,Y] = meshgrid(x,y)
[X,Y] = meshgrid(x)
[X,Y,Z] = meshgrid(x,y,z)

Description for meshgrid matlab Function

  • meshgrid function will help to trans transforms the given domain which is specified by the  x and y into arrays X and Y and these array can be used to check the two variables and three-dimensional mesh/surface plots.
  •  Output rows of array X will be copies of x vector; same as the columns  output array Y will be copies of y vector
  •  [X,Y] = meshgrid(x) is like [X,Y] = meshgrid(x,x).
  •  [X,Y,Z] = meshgrid(x,y,z) helps to produces the three-dimensional arrays which is used to check the desired functions of three variables and three-dimensional volumetric plots.

 Important Note for meshgrid matlab Function

  •  The meshgrid function in MATLAB is same as the ndgrid function but the point that should be remembered that is "in meshgrid function the order of  first two input and output arguments is switched"

     [X,Y,Z] = meshgrid(x,y,z)

gives the same result as

    [Y,X,Z] = ndgrid(y,x,z)

  •   meshgrid function in MATLAB is surely suited for two- or three-dimensional Cartesian space.
  •  ndgrid fucntion in MATLAB is suited for multidimensional problems that are not spatially based.

 Example for meshgrid matlab Function

    [X,Y] = meshgrid(1:3,10:14)

    X =

         1     2     3
         1     2     3
         1     2     3
         1     2     3
         1     2     3

    Y =

        10    10    10
        11    11    11
        12    12    12
        13    13    13
        14    14    14

use meshgrid to create a surface plot of a function.

    [X,Y] = meshgrid(-2:.2:2, -2:.2:2);                                
    Z = X .* exp(-X.^2 - Y.^2);                                        
    surf(X,Y,Z)


meshgrid to create a surface plot of a function.
meshgrid to create a surface plot of a function.