How to Plot 3D in MATLAB (2024)

  1. Use the mesh() Function to Create Surface Plots in MATLAB
  2. Use the scatter3() Function to Create a 3D Scatter Plot in MATLAB
  3. Use the contour3() Function to Create a 3D Contour Plot in MATLAB
  4. Use the plot3() Function to Create a 3D Plot of Point or Line in MATLAB
  5. Use the quiver3() Function to Create a 3D Quiver or Vector Plot in MATLAB
  6. Use the bar3() Function to Create a 3D Bar Graph in MATLAB
How to Plot 3D in MATLAB (1)

This tutorial will discuss creating 3d plots using the mesh(), scatter3(), contour3(), plot3(), quiver3(), and bar3() functions in MATLAB.

Use the mesh() Function to Create Surface Plots in MATLAB

Matlab’s built-in function mesh() creates the surface plots on a 3D plane. We can pass the matrix inside the mesh() function as a function that we want to plot in the 3D plane.

The mesh() function will plot the given matrix along the z-axis using the default value for the x-y coordinates. The x and y coordinates will be from the indices of the given matrix.

The given matrix will be plotted on the z-axis as heights on a three-dimensional plane.

For example, let’s create a matrix Z and plot it on the surface plot using the mesh() function in Matlab.

See the code below.

clc[x,y] = meshgrid(-18:1:18);r = sqrt(x.^2 + y.^2)/2;z = cos(r)./r;mesh(x,y,z)

Output:

How to Plot 3D in MATLAB (2)

Use the scatter3() Function to Create a 3D Scatter Plot in MATLAB

If we want to create a 3D scatter plot, we can use the scatter3() function. This function is the same as the scatter() function, though it plots the given data in a 3D plane.

We can give two or three input vectors to the scatter3() function.

In the case of three inputs, the first vector contains the x coordinates, the second contains the y coordinates, and the third contains the z coordinates.

In the case of two input vectors, the third coordinate z will be taken from the indices of the first two coordinates.

For example, let’s plot a scatter plot in a 3D place using the scatter3() function.

See the code below.

clcx = linspace(0,2*pi,100);y = sin(x) + rand(1,100);z = 1:100;scatter3(x,y,z)

Output:

How to Plot 3D in MATLAB (3)

Check this link for more details about the scatter() function.

Use the contour3() Function to Create a 3D Contour Plot in MATLAB

We can use Matlab’s built-in function contour3() to create a 3D contour plot. A contour plot is a plot of isolines with different colors according to values.

The color given to the line depends on its value. The colder color corresponds to low values, and the hotter color corresponds to high values.

For example, let’s plot a 3D contour plot of a sphere using the sphere() and the contour3() function. See the code below.

clc[x,y,z] = sphere(100);contour3(x,y,z);

Output:

How to Plot 3D in MATLAB (4)

Use the plot3() Function to Create a 3D Plot of Point or Line in MATLAB

We already know about the plot() function in Matlab, which is used to plot data on a 2D plane. The plot3() function is similar to the plot() function.

The only difference is that the plot3() function plots data on a 3D plane. We can plot data as a line, aka a continuous plot, and as points, aka a discrete plot.

We have to pass three coordinates, x, y, and z, to plot the data on a 3D plane. For example, let’s plot a helix in 3D using the plot3() function.

See the code below.

clct = 0:pi/50:10*pi;sinet = sin(t);cost = cos(t);plot3(sinet,cost,t)

Output:

How to Plot 3D in MATLAB (5)

Check this link for more details about the plot3() function.

Use the quiver3() Function to Create a 3D Quiver or Vector Plot in MATLAB

Matlab’s built-in function quiver3() can be used to plot a 3D quiver or vector plot. A scalar consists of only magnitude, but a vector contains magnitude and direction.

We can create a 3D plot of scalar data using the plot3() function, but we cannot plot vector data using the plot3() function because the function will not plot the direction of the vector.

In the case of vector, we can use the quiver3() function, which will plot the magnitude and direction of the vector.

For example, let’s create a matrix and plot it on a 3D plane with direction. See the code below.

clcm = [1:10 ;10:-1:1;1:10];quiver3(m,m,m,m)

Output:

How to Plot 3D in MATLAB (6)

Check this link for more details about the quiver3() function.

Use the bar3() Function to Create a 3D Bar Graph in MATLAB

We can use Matlab’s built-in function bar3() to plot a bar graph in a 3D plane. We must pass the data’s input matrix, plotted as heights on the z-axis in a 3D plane.

The other two coordinates (x and y) will be taken from the indices of the given matrix. For example, let’s create a 3D bar graph from a given matrix.

See the code below.

clcm = [1:10 ;10:-1:1;1:10];bar3(m)

Output:

How to Plot 3D in MATLAB (7)

Check this link for more details about the bar3() function.

How to Plot 3D in MATLAB (2024)

References

Top Articles
Ayna Khalaf Leaks
American Airlines Hubs: Guide to AA's Hub Cities
Myexperience Login Northwell
Atvs For Sale By Owner Craigslist
Arrests reported by Yuba County Sheriff
Citi Card Thomas Rhett Presale
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
What Was D-Day Weegy
Detroit Lions 50 50
Aces Fmc Charting
Skylar Vox Bra Size
Craigslist Pets Sac
Guilford County | NCpedia
Log in or sign up to view
Star Wars: Héros de la Galaxie - le guide des meilleurs personnages en 2024 - Le Blog Allo Paradise
Plan Z - Nazi Shipbuilding Plans
The Grand Canyon main water line has broken dozens of times. Why is it getting a major fix only now?
Copart Atlanta South Ga
Robert Deshawn Swonger Net Worth
Wemod Vampire Survivors
UMvC3 OTT: Welcome to 2013!
Vernon Dursley To Harry Potter Nyt Crossword
Jesus Revolution Showtimes Near Regal Stonecrest
Cowboy Pozisyon
Unreasonable Zen Riddle Crossword
Pokémon Unbound Starters
Healthy Kaiserpermanente Org Sign On
Himekishi Ga Classmate Raw
R/Mp5
Amazing Lash Bay Colony
What Is The Lineup For Nascar Race Today
Fedex Walgreens Pickup Times
Wega Kit Filtros Fiat Cronos Argo 1.8 E-torq + Aceite 5w30 5l
Fox And Friends Mega Morning Deals July 2022
Gyeon Jahee
Directions To 401 East Chestnut Street Louisville Kentucky
Scanning the Airwaves
Myfxbook Historical Data
Dcilottery Login
Aita For Announcing My Pregnancy At My Sil Wedding
Thor Majestic 23A Floor Plan
Bmp 202 Blue Round Pill
Pas Bcbs Prefix
Stephen Dilbeck, The First Hicks Baby: 5 Fast Facts You Need to Know
The Latest Books, Reports, Videos, and Audiobooks - O'Reilly Media
Powah: Automating the Energizing Orb - EnigmaticaModpacks/Enigmatica6 GitHub Wiki
Verilife Williamsport Reviews
Laurel Hubbard’s Olympic dream dies under the world’s gaze
Blippi Park Carlsbad
Generator für Fantasie-Ortsnamen: Finden Sie den perfekten Namen
Ranking 134 college football teams after Week 1, from Georgia to Temple
Honeybee: Classification, Morphology, Types, and Lifecycle
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 6750

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.