how to draw a 3d heart in matlab
Did you ever wonder seeing astonishing 3D graphs in MATLAB? How to draw multiple 3D plot graphs in MATLAB?
This is an in-depth tutorial for you. I will explain the different MATLAB 3D plot examples and how to depict 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 about information technology.
This tutorial provides you the plot'southward functions, syntax, and code, for example for the five primary dissimilar types of 3D plots. At the end of this post, you will be able to draw your ain 3D plot graph in MATLAB.
Information technology'southward amazing. Right?
Let'due south start.
3D MATLAB Plot Introduction
In general, the three-dimensional plots consist of the iii vectors (ten,y,z) in the same graph.
In MATLAB, the plot3() part is used to draw the 3D plot graph. You can likewise apply a specified line style, mark, and color for drawing 3D plots.
The general syntax to brandish the 3D plot is,
plot3(x,y,z) plot3(x,y,z,Name) plot3(ten,y,z,LineSpec)
Let's showtime cartoon different types of the 3D plot graph…
Classifications of Iii-Dimensional Plots | MATLAB 3D plot Examples
Hither, we are considering, the 5 principal different types of three-dimensional (3D) plots. These graphs are mostly used in the industry.
The post-obit list of different 3D plots as,
- Mesh Plot
- Surface Plot
- Ribbon PLot
- Contour Plot
- Slice Plot
Equally a part of this tutorial nigh MATLAB 3D plot examples, I am describing the topmost five 3D plots one-by-one.
one. Mesh 3D Plot in MATLAB
The mesh plotting function 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, you need to pass the array values to the mesh function.
Syntax:
Mesh function transforms the domain specified by vectors (Ten, Y, Z) into arrays (ten,y,z).
The syntax for the Mesh Plot is,
mesh(10,y,z) [X,Y,Z] = meshgrid(x,y,z)
MATLAB Code:
As an example, we are plotting the mesh 3D plot for square root mathematical function.
[x,y] = meshgrid(-10:0.1:ten); t = sqrt(x.^ii+y.^two); z =(10*sin(t)); mesh(x,y,z)
Output in MATLAB:
See hither, you get a colorful and smooth connecting surface line of three-dimensional [3D] Mesh plot.
You can also plot the graph for various Mathematical Expressions in MATLAB.
2. Surface 3D Plot in MATLAB
A surface plot is somewhat similar to a mesh plot. The master difference betwixt them is, in the surface plot, the connecting lines and the faces both volition be displayed in the dark colour.
How to create the Surf plot in MATLAB?
Syntax:
In the surface plot, 'surf' office is used. So, yous tin write a uncomplicated format similar 'part name(array)'.
surf(10,y,z) surf(z)
MATLAB Code:
Let's write a MATLAB code for the 3-dimensional surface plot for an exponential role exp().
[x,y] = peaks(30); z = exp(-0.ix*(10.^2+0.5*(x-y).^2)); surf(x,y,z); xlabel('\bf Ten centrality'); ylabel('\bf Y centrality'); zlabel('\bf Z centrality'); title('\bf Surface Plot') colorbar
Output in MATLAB:
After the getting output of surface plot, you will see the connecting lines and the faces are both displayed in the same shade.
3. Ribbon 3D Plot in MATLAB
As the name ribbon, this 3D plot graph will exist having different color ribbons.
How to create the ribbon plot in MATLAB?
Here, nosotros are using ribbon() office for plotting ribbon 3D MATLAB plot.
Syntax:
The general syntax for writing code,
ribbon(x,y,z) ribbon(x,y) ribbon(z)
MATLAB Code:
To create a ribbon plot using peak function for mathematical role ((10²)-(y²))
[ten,y] = peaks(30); z =[(x.^2)-(y.^2)]; ribbon(z); title('\bf Ribbon Plot')
Output in MATLAB:
You tin can run across each and every colorful shade ribbons.
iv. Contour 3D Plot in MATLAB
How to create the three dimensional [3D] contour plot?
To create the 3 dimensional [3D] contour plot, we are using the 'contour3' role.
Note: You tin can plot the Contour 2D plot by using the but 'profile' part.
Syntax:
The syntax for the three-dimensional contour plot,
contour3(x,y,z) contour3(z)
MATLAB Code:
Nosotros are plotting the contour plot for the exponential mathematical equation is (exp( x²-y²)).
[x,y] = peaks(30); z = exp(-x.^two-y.^ii); contour3(x,y,z); title('\bf Profile Plot')
Output in MATLAB:
Below is a diagram for three dimensional [3D] profile plot.
five. Slice 3D Plot in MATLAB
For plotting slice graph, y'all must know volumetric data(v), specification of 3-dimensional coordinate (x,y,z), and 'xslice, yslice, zslice'.
Syntax:
Slice plot's syntax is
piece(x,y,z,v,xslice,yslice,zslice) slice(5,xslice,yslice,zslice)
Where,
- xslice- 'x' coordinate data for slice plot
- yslice- 'y' coordinate data for slice plot
- zslice- 'z' coordinate data for piece plot
MATLAB Code:
Slice plot is picayune different from other 3D plots types. When you lot are writing MATLAB code for Piece plot, you need to specify each coordinator value.
Let'south draw the slite plot graph for an exponential mathematical equation.
[x,y,z] = meshgrid(-10:.ii:ten); v = [exp((x.^ii)-(y.^3)-(z.^v))]; xslice = 0.1; yslice = v; zslice = 0; slice(x,y,z,v,xslice,yslice,zslice) colorbar title('\bf Slice Plot')
Output in MATLAB:
The output looks like the below pic.
These are the topmost three dimensional [3D] used in the industry projects.
This is all nearly different MATLAB 3D plot examples. I accept explained the different classification of MATLAB 3D plots with simple code and syntax.
If you have doubt, write in the comment. I will reply to yous every bit before long equally possible.
Other MATLAB Tutorials:
- MATLAB Math Functions
- MATLAB M-File Details
- Matrix in MATLAB
- Vector in MATLAB
- MATLAB/ Simulink Toolbox
- Awarding of MATLAB/Simulink
Thank you for Reading!
I take completed chief in Electrical Ability System. I work and write technical tutorials on the PLC, MATLAB programming, and Electrical on DipsLab.com portal.
Sharing my cognition 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 a 3d heart in matlab"
Post a Comment