MATLAB is an incredibly useful mathematical and engineering computer software program capable of carrying out advanced mathematical calculations and performing engineering simulations. One of its more useful functions is plotting data, in 2-D or 3-D. There are two main kinds of 3-D plotting in MATLAB: line graphs and surface plots. Line graphs trace the path of a single line through three dimensions. Surface plots create three-dimensional surfaces based on data from corresponding elements of two matrices.
- Skill level:
- Moderately Easy
Other People Are Reading
Define a range of values for a certain variable. For example, type "t = 0:pi/50:10*pi;" This defines "t" as a variable that increases from zero to 10 times pi in increments of fiftieths of pi.
Define two functions of "t." For example, "x = sin(t)" and "y = cos(t)".
Plot a three-dimensional helix using the PLOT3 command by typing "plot 3(sin(t),cos(t),t)." Notice the function takes the form "plot 3(x,y,z)" where MATLAB determines the xy position for each z-coordinate by looking at the first two arguments of the PLOT3 function.
3-D Line Plots
Define a matrix of values for the x-coordinate argument of the SURF function. To generate a random 10 by 10 matrix, type "x = magic(10)."
Define a matrix of values for the y-coordinate argument of the SURF function. To generate another random 10 by 10 matrix, type "y = magic(10) - 100."
Define the z-coordinate based on the x and y coordinates. For example, type "z = x.^2 + y.^2"
Graph a 3D surface plot now by typing "surf(x,y,z)"
3-D Surface Plots
Tips and warnings
- Get a quick idea of how impressive a surface plot can look by entering this special function:
- [x,y,z] = peaks(30);
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for