# Creating 3D Plot Surface Domains From Vectors In Matlab®(Illustrated Expression)

by,

3D illustrations and graphs are very important in data analyses. To plot 3D graphs, you need to have 3 variables. To plot 3D graphs in Matlab®, you need to create a 3D plot area and surface first. You can do this in Matlab® with the ‘meshgrid()’ command. Here, we show you how to create 3D plot surfaces in Matlab® with the ‘meshgrid()’ command.

YOU CAN LEARN MatLab® IN MECHANICAL BASE; Click And Start To Learn MatLab®!

## How To Use ‘meshgrid()’ Command In Matlab®?

``````>> x = -pi:5;
y = 0:0.4:2;
[X, Y] =meshgrid(x,y)

X =

Columns 1 through 5

-3.1416   -2.1416   -1.1416   -0.1416    0.8584
-3.1416   -2.1416   -1.1416   -0.1416    0.8584
-3.1416   -2.1416   -1.1416   -0.1416    0.8584
-3.1416   -2.1416   -1.1416   -0.1416    0.8584
-3.1416   -2.1416   -1.1416   -0.1416    0.8584
-3.1416   -2.1416   -1.1416   -0.1416    0.8584

Columns 6 through 9

1.8584    2.8584    3.8584    4.8584
1.8584    2.8584    3.8584    4.8584
1.8584    2.8584    3.8584    4.8584
1.8584    2.8584    3.8584    4.8584
1.8584    2.8584    3.8584    4.8584
1.8584    2.8584    3.8584    4.8584

Y =

Columns 1 through 5

0         0         0         0         0
0.4000    0.4000    0.4000    0.4000    0.4000
0.8000    0.8000    0.8000    0.8000    0.8000
1.2000    1.2000    1.2000    1.2000    1.2000
1.6000    1.6000    1.6000    1.6000    1.6000
2.0000    2.0000    2.0000    2.0000    2.0000

Columns 6 through 9

0         0         0         0
0.4000    0.4000    0.4000    0.4000
0.8000    0.8000    0.8000    0.8000
1.2000    1.2000    1.2000    1.2000
1.6000    1.6000    1.6000    1.6000
2.0000    2.0000    2.0000    2.0000

>> ``````

As we stated above, you need to have 3 variables to plot 3D graphs. So you need to have two independent variable sets as vectors, for example, ‘x’ and ‘y’ here we created as shown above. Your third variable must be dependent on these variables. So, to illustrate the third variable that changes according to ‘x’ and ‘y’, you need to create a 3D domain to show this change.

YOU CAN LEARN MatLab® IN MECHANICAL BASE; Click And Start To Learn MatLab®!

This 3D domain is created with the help of two ‘x’ and ‘y’ variables with the ‘meshgrid()’ command in Matlab®. This domain constitutes ‘X’ and ‘Y’ matrices that are created with dimensions of ‘x’ and ‘y’ vectors. We just typed ‘X’ and ‘Y’ result matrices, which will be our matrice domains. Then we equate this with the ‘meshgrid()’ command and typed ‘x’ and ‘y’ vectors inside that command as shown above. Domain matrices are created.

• The scale of vector ‘y’, defines the row number of ‘X’.
• The scale of vector ‘x’ defines the column number of ‘Y’.
• Columns of ‘X’ are the elements of vector ‘x’.
• Rows of ‘Y’ are the elements of ‘y’.

The logic behind the creation of domain matrices of 3D plots in Matlab® with the ‘meshgrid()’ command is like that.

## Conclusion

Do not forget to leave your comments and questions about the ‘meshgrid()’ command in Matlab® below. Your feedback is very important for us.