how to draw 3d plot in matlab
Did you always wonder seeing astonishing 3D graphs in MATLAB? How to draw multiple 3D plot graphs in MATLAB?
This is an in-depth tutorial for y'all. I will explain the unlike MATLAB 3D plot examples and how to draw them.
This tutorial is an extension of a previous tutorial two-dimensional [2D] MATLAB plot.
When I share the 2d plot graph tutorial, some of the readers asked me about the 3D plot. And I decided to write almost it.
This tutorial provides you the plot's functions, syntax, and lawmaking, for example for the five primary unlike types of 3D plots. At the end of this postal service, you volition be able to draw your own 3D plot graph in MATLAB.
It's amazing. Correct?
Allow's starting time.
3D MATLAB Plot Introduction
In general, the iii-dimensional plots consist of the 3 vectors (10,y,z) in the same graph.
In MATLAB, the plot3() function is used to draw the 3D plot graph. You tin also use a specified line manner, marker, and color for drawing 3D plots.
The general syntax to brandish the 3D plot is,
plot3(10,y,z) plot3(x,y,z,Name) plot3(x,y,z,LineSpec)
Let's start drawing dissimilar types of the 3D plot graph…
Classifications of 3-Dimensional Plots | MATLAB 3D plot Examples
Here, we are considering, the five main dissimilar types of three-dimensional (3D) plots. These graphs are mostly used in the industry.
The following list of different 3D plots as,
- Mesh Plot
- Surface Plot
- Ribbon PLot
- Contour Plot
- Slice Plot
Equally a part of this tutorial virtually MATLAB 3D plot examples, I am describing the topmost five 3D plots one-by-one.
one. Mesh 3D Plot in MATLAB
The mesh plotting office is used to display the mesh plot. It produces a wireframe surface where the lines connecting the defining points are colored.
How to create the Mesh plot in MATLAB?
For the mesh plotting in MATLAB, yous need to laissez passer the array values to the mesh function.
Syntax:
Mesh function transforms the domain specified by vectors (10, Y, Z) into arrays (x,y,z).
The syntax for the Mesh Plot is,
mesh(x,y,z) [X,Y,Z] = meshgrid(x,y,z)
MATLAB Code:
As an example, nosotros are plotting the mesh 3D plot for foursquare root mathematical function.
[x,y] = meshgrid(-x:0.one:10); t = sqrt(ten.^ii+y.^two); z =(10*sin(t)); mesh(ten,y,z)
Output in MATLAB:
See here, you go a colorful and polish connecting surface line of three-dimensional [3D] Mesh plot.
You can besides plot the graph for diverse Mathematical Expressions in MATLAB.
2. Surface 3D Plot in MATLAB
A surface plot is somewhat similar to a mesh plot. The primary difference between them is, in the surface plot, the connecting lines and the faces both will be displayed in the dark color.
How to create the Surf plot in MATLAB?
Syntax:
In the surface plot, 'surf' part is used. So, you lot tin can write a elementary format like 'office proper noun(assortment)'.
surf(x,y,z) surf(z)
MATLAB Code:
Let's write a MATLAB lawmaking for the three-dimensional surface plot for an exponential function exp().
[ten,y] = peaks(30); z = exp(-0.9*(x.^2+0.5*(x-y).^two)); surf(x,y,z); xlabel('\bf X axis'); ylabel('\bf Y axis'); zlabel('\bf Z axis'); championship('\bf Surface Plot') colorbar
Output in MATLAB:
After the getting output of surface plot, you lot will see the connecting lines and the faces are both displayed in the same shade.
3. Ribbon 3D Plot in MATLAB
Equally the name ribbon, this 3D plot graph volition be having different color ribbons.
How to create the ribbon plot in MATLAB?
Here, nosotros are using ribbon() function for plotting ribbon 3D MATLAB plot.
Syntax:
The full general syntax for writing lawmaking,
ribbon(x,y,z) ribbon(x,y) ribbon(z)
MATLAB Lawmaking:
To create a ribbon plot using meridian function for mathematical office ((x²)-(y²))
[x,y] = peaks(30); z =[(10.^2)-(y.^two)]; ribbon(z); title('\bf Ribbon Plot')
Output in MATLAB:
You can run across each and every colorful shade ribbons.
4. Contour 3D Plot in MATLAB
How to create the three dimensional [3D] profile plot?
To create the 3 dimensional [3D] contour plot, we are using the 'contour3' function.
Note: You tin plot the Profile second plot past using the only 'contour' function.
Syntax:
The syntax for the 3-dimensional contour plot,
contour3(ten,y,z) contour3(z)
MATLAB Code:
We are plotting the contour plot for the exponential mathematical equation is (exp( ten²-y²)).
[ten,y] = peaks(30); z = exp(-x.^2-y.^ii); contour3(x,y,z); championship('\bf Profile Plot')
Output in MATLAB:
Below is a diagram for iii dimensional [3D] profile plot.
v. Slice 3D Plot in MATLAB
For plotting piece graph, you must know volumetric data(v), specification of three-dimensional coordinate (10,y,z), and 'xslice, yslice, zslice'.
Syntax:
Slice plot's syntax is
slice(x,y,z,five,xslice,yslice,zslice) slice(five,xslice,yslice,zslice)
Where,
- xslice- 'x' coordinate information for slice plot
- yslice- 'y' coordinate data for slice plot
- zslice- 'z' coordinate data for slice plot
MATLAB Code:
Slice plot is picayune different from other 3D plots types. When you are writing MATLAB code for Slice plot, you demand to specify each coordinator value.
Let's depict the slite plot graph for an exponential mathematical equation.
[x,y,z] = meshgrid(-10:.2:x); v = [exp((x.^ii)-(y.^3)-(z.^v))]; xslice = 0.ane; yslice = 5; zslice = 0; slice(10,y,z,five,xslice,yslice,zslice) colorbar title('\bf Piece Plot')
Output in MATLAB:
The output looks like the below moving-picture show.
These are the topmost three dimensional [3D] used in the industry projects.
This is all about dissimilar MATLAB 3D plot examples. I have explained the different nomenclature of MATLAB 3D plots with simple lawmaking and syntax.
If y'all have doubtfulness, write in the annotate. I volition answer to you as soon as possible.
Other MATLAB Tutorials:
- MATLAB Math Functions
- MATLAB M-File Details
- Matrix in MATLAB
- Vector in MATLAB
- MATLAB/ Simulink Toolbox
- Application of MATLAB/Simulink
Thanks for Reading!
I take completed master in Electric Power System. I work and write technical tutorials on the PLC, MATLAB programming, and Electrical on DipsLab.com portal.
Sharing my knowledge on this blog makes me happy. And sometimes I delve in Python programming.
Source: https://dipslab.com/matlab-3d-plot-examples/
0 Response to "how to draw 3d plot in matlab"
Post a Comment