Skip to content Skip to sidebar Skip to footer

how to draw 3d graphics in matlab

MATLAB Programming Feature image

Did y'all ever wonder seeing amazing 3D graphs in MATLAB? How to draw multiple 3D plot graphs in MATLAB?

This is an in-depth tutorial for yous. I will explain the dissimilar 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 about it.

This tutorial provides you the plot's functions, syntax, and lawmaking, for example for the five primary dissimilar types of 3D plots. At the end of this post, you will be able to depict your own 3D plot graph in MATLAB.

It'due south amazing. Right?

Allow's start.

3D MATLAB Plot Introduction

In full general, the three-dimensional plots consist of the three vectors (x,y,z) in the same graph.

In MATLAB, the plot3() function is used to draw the 3D plot graph. You lot tin can also apply a specified line fashion, mark, and color for drawing 3D plots.

The full general syntax to display the 3D plot is,

plot3(x,y,z)  plot3(x,y,z,Name)  plot3(ten,y,z,LineSpec)

Permit's showtime drawing dissimilar types of the 3D plot graph…

 Classifications of Three-Dimensional Plots | MATLAB 3D plot Examples

Here, nosotros are considering, the five main different types of three-dimensional (3D) plots. These graphs are by and large used in the industry.

The post-obit list of  different 3D plots every bit,

  1. Mesh Plot
  2. Surface Plot
  3. Ribbon PLot
  4. Profile Plot
  5. Slice Plot

As a part of this tutorial almost MATLAB 3D plot examples, I am describing the topmost five 3D plots ane-by-ane.

1. 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 lot need to pass the assortment values to the mesh office.

Syntax:

Mesh office transforms the domain specified by vectors (10, 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 Lawmaking:

As an example, we are plotting the mesh 3D plot for foursquare root mathematical role.

[x,y] = meshgrid(-10:0.1:10);  t = sqrt(ten.^ii+y.^2); z =(10*sin(t)); mesh(x,y,z)

Output in MATLAB:

Encounter here, y'all go a colorful and polish connecting surface line of three-dimensional [3D] Mesh plot.

Yous can also plot the graph for various Mathematical Expressions in MATLAB.

two. Surface 3D Plot in MATLAB

A surface plot is somewhat similar to a mesh plot. The main difference between them is, in the surface plot, the connecting lines and the faces both volition be displayed in the dark color.

How to create the Surf plot in MATLAB?

Syntax:

In the surface plot, 'surf' function is used. So, yous can write a simple format like 'function name(assortment)'.

surf(10,y,z)  surf(z)

MATLAB Code:

Let'southward write a MATLAB code for the 3-dimensional surface plot for an exponential function exp().

[x,y] = peaks(30); z = exp(-0.ix*(10.^two+0.five*(x-y).^ii)); surf(x,y,z); xlabel('\bf 10 axis'); ylabel('\bf Y centrality'); zlabel('\bf Z axis'); championship('\bf Surface Plot') colorbar

Output in MATLAB:

After the getting output of surface plot, y'all will see the connecting lines and the faces are both displayed in the aforementioned shade.

three. Ribbon 3D Plot in MATLAB

As the name ribbon, this 3D plot graph will be having different color ribbons.

How to create the ribbon plot in MATLAB?

Here, we are using ribbon() function for plotting ribbon 3D MATLAB plot.

Syntax:

The general syntax for writing code,

ribbon(x,y,z) ribbon(ten,y) ribbon(z)

MATLAB Code:

To create a ribbon plot using peak function for mathematical function  ((ten²)-(y²))

[x,y] = peaks(30); z =[(x.^two)-(y.^ii)]; ribbon(z); title('\bf Ribbon Plot')

Output in MATLAB:

You tin can see 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' function.

Note: You tin can plot the Contour 2d plot past using the only 'profile' role.

Syntax:

The syntax for the three-dimensional contour plot,

contour3(10,y,z) contour3(z)

MATLAB Lawmaking:

Nosotros are plotting the contour plot for the exponential mathematical equation is (exp( ten²-y²)).

[x,y] = peaks(thirty); z = exp(-x.^2-y.^2); contour3(ten,y,z); title('\bf Contour Plot')

Output in MATLAB:

Below is a diagram for 3 dimensional [3D] contour plot.

v. Slice 3D Plot in MATLAB

For plotting slice graph, you lot must know volumetric data(v), specification of iii-dimensional coordinate (ten,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- '10' coordinate data for slice plot
  • yslice- 'y' coordinate information for slice plot
  • zslice- 'z' coordinate data for slice plot

MATLAB Code:

Slice plot is niggling different from other 3D plots types. When y'all are writing MATLAB code for Piece plot, you lot need to specify each coordinator value.

Let's describe the slite plot graph for an exponential mathematical equation.

[x,y,z] = meshgrid(-10:.2:10); v = [exp((ten.^2)-(y.^3)-(z.^5))]; xslice = 0.1;  yslice = 5; zslice = 0; slice(x,y,z,v,xslice,yslice,zslice) colorbar title('\bf Slice Plot')

Output in MATLAB:

The output looks similar the below picture.

These are the topmost iii dimensional  [3D] used in the industry projects.

This is all almost different MATLAB 3D plot examples. I have explained the different nomenclature of MATLAB 3D plots with uncomplicated code and syntax.

If y'all take doubt, write in the comment. I will reply to yous 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!

mahonfacturtel02.blogspot.com

Source: https://dipslab.com/matlab-3d-plot-examples/

Post a Comment for "how to draw 3d graphics in matlab"