how to draw 3d graphs using matlab

MATLAB Programming Feature image

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 volition explain the different MATLAB 3D plot examples and how to describe 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 v main dissimilar types of 3D plots. At the end of this post, you will be able to describe your own 3D plot graph in MATLAB.

Information technology's amazing. Right?

Let'southward beginning.

3D MATLAB Plot Introduction

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

In MATLAB, the plot3() office is used to draw the 3D plot graph. Yous tin can also use a specified line mode, marking, and color for cartoon 3D plots.

The general syntax to display the 3D plot is,

plot3(ten,y,z)  plot3(x,y,z,Proper name)  plot3(10,y,z,LineSpec)

Let's start drawing different types of the 3D plot graph…

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

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

The following list of  unlike 3D plots equally,

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

As a function of this tutorial nearly MATLAB 3D plot examples, I am describing the topmost five 3D plots 1-by-one.

1. Mesh 3D Plot in MATLAB

The mesh plotting part 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 (X, Y, Z) into arrays (10,y,z).

The syntax for the Mesh Plot is,

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

MATLAB Code:

Equally an example, we are plotting the mesh 3D plot for square root mathematical function.

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

Output in MATLAB:

Run into here, you become a colorful and smooth 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 like to a mesh plot. The main difference between them is, in the surface plot, the connecting lines and the faces both will be displayed in the night color.

How to create the Surf plot in MATLAB?

Syntax:

In the surface plot, 'surf' function is used. And then, you can write a unproblematic format like 'function name(array)'.

surf(ten,y,z)  surf(z)

MATLAB Code:

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

[x,y] = peaks(xxx); z = exp(-0.9*(10.^2+0.5*(x-y).^2)); surf(x,y,z); xlabel('\bf X axis'); ylabel('\bf Y axis'); zlabel('\bf Z axis'); championship('\bf Surface Plot') colorbar

Output in MATLAB:

Afterwards the getting output of surface plot, y'all will run across the connecting lines and the faces are both displayed in the same shade.

iii. 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() role 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 meridian function for mathematical part  ((x²)-(y²))

[x,y] = peaks(thirty); 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.

4. Contour 3D Plot in MATLAB

How to create the 3 dimensional [3D] contour plot?

To create the three dimensional [3D] contour plot, we are using the 'contour3' function.

Note: Yous tin can plot the Contour 2D plot by using the only 'contour' part.

Syntax:

The syntax for the 3-dimensional profile plot,

contour3(x,y,z) contour3(z)

MATLAB Code:

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

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

Output in MATLAB:

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

5. Slice 3D Plot in MATLAB

For plotting slice graph, you must know volumetric data(v), specification of three-dimensional coordinate (ten,y,z), and 'xslice, yslice, zslice'.

Syntax:

Piece plot's syntax is

slice(ten,y,z,v,xslice,yslice,zslice)  slice(v,xslice,yslice,zslice)

Where,

  • xslice- 'x' coordinate data for piece plot
  • yslice- 'y' coordinate data for slice plot
  • zslice- 'z' coordinate data for slice plot

MATLAB Code:

Slice plot is piddling dissimilar from other 3D plots types. When you are writing MATLAB code for Piece plot, you need to specify each coordinator value.

Let'southward draw the slite plot graph for an exponential mathematical equation.

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

Output in MATLAB:

The output looks like the beneath movie.

These are the topmost three dimensional  [3D] used in the manufacture projects.

This is all about different MATLAB 3D plot examples. I have explained the different classification of MATLAB 3D plots with simple code and syntax.

If y'all have uncertainty, write in the comment. I will reply to you lot every bit soon every bit possible.

Other MATLAB Tutorials:

  • MATLAB Math Functions
  • MATLAB K-File Details
  • Matrix in MATLAB
  • Vector in MATLAB
  • MATLAB/ Simulink Toolbox
  • Application of MATLAB/Simulink

Thank you for Reading!

montoyahaversidne.blogspot.com

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

0 Response to "how to draw 3d graphs using matlab"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel