3D Plots in MATLAB (original) (raw)

Last Updated : 9 May, 2021

In MATLAB, we can plot different types of modules like 2d plotting and 3d plotting. In this article, we will see what are the various types of 3D plotting.

Syntax:

mesh(Z)

Example:

Matlab `

% give the input of x and y. [x,y]= meshgrid(0:0.1:5);

% give the expression for x % and y for the output in z z= sin(x).*cos(y);

% mesh() is used for 3D plotting mesh(z);

`

Output:

Syntax:

surf(Z)

Example:

Matlab `

% give the input for x and y [x,y]= meshgrid(0:0.1:5);

% give the expression for % x and y for the value of z. z= sin(x).*cos(y);

% use surf() for the plotting surf(z)

`

Output:

Syntax:

surfl(z)

There are three types of shading available:

  1. shading flat
  2. shading faceted
  3. shading interp

Example:

Matlab `

% give the input for x and y [x,y]= meshgrid(0:0.1:5);

% give the expression for x and y % for the value of z z= sin(x).*cos(y);

% use surfl() for the plotting % shading faceted is by default surfl(z) shading faceted title('Faceted Shading')

% use shading flat for each mesh % line segment and face has a % constant color surfl(z) shading flat title('Flat Shading')

% use shading flat for varies the % color in each line segment and % face by interpolating surfl(z) shading interp title('Interpolated Shading')

`

Output:

Syntax:

contour(Z)

Example:

Matlab `

% enter the inputs of x and y [x,y]= meshgrid(0:0.1:5);

% enter the expression using % x and y z= sin(x).*cos(y);

% use contour() for plotting contour3(z,50)

`

Output:

Syntax:

quiver3(X, Y, Z, U, V, W)

Example:

Matlab `

% give the input value for x, % y and z [x,y,z]= meshgrid(0:0.1:5);

% using x, y and z give the % values for u,v and w u= sin(x).*cos(y); v= sin(x).*cos(y); w= sin(x).*cos(y);

%use quiver3() for 3d plotting quiver3(x,y,z,u,v,w);

`

Output: