How to Make 3D Plots Using MATLAB

Whether it's for research, a school assignment, or a work presentation, 3-D plots are great for visualizing what a complicated set of data looks like. With the help of MATLAB (Matrix Laboratory), you'll be able to create stunning 3-D...
Part 1 of 3:

Constructing the Domain

  1. How to Make 3D Plots Using MATLAB Picture 1How to Make 3D Plots Using MATLAB Picture 1
    Open the command window. In the default layout this should appear automatically as the biggest window displayed.
  2. How to Make 3D Plots Using MATLAB Picture 2How to Make 3D Plots Using MATLAB Picture 2
    If the command window isn't present, select home in the upper left corner. Afterwards, select layout and then "Default".
  3. How to Make 3D Plots Using MATLAB Picture 3How to Make 3D Plots Using MATLAB Picture 3
    In the command window, define both of your x and y vectors.
    1. This is typically done in the form of x=[vector or function] and y=[vector or function]
    2. Remember to use the dot operator when multiplying or dividing vectors and matrices. Otherwise errors will occur.
Part 2 of 3:

Producing the Grid in the xy-Plane

  1. How to Make 3D Plots Using MATLAB Picture 4How to Make 3D Plots Using MATLAB Picture 4
    Define a relationship between x and y. In order to accomplish this, two commands must be used.
    1. The first is the mesh function. By using this, the result will be a wireframe mesh graph.
    2. The other is the surf function. When using surf, the result will be a 3-D surface plot.
  2. How to Make 3D Plots Using MATLAB Picture 5How to Make 3D Plots Using MATLAB Picture 5
    When using mesh, input meshgrid to the command window.
    1. The command will be formatted as follows: [xx,yy]=meshgrid(x,y).
    2. In the workspace window you will see that the variables xx and yy have been defined.
Part 3 of 3:

Defining "zz" and Plotting the Surface

  1. How to Make 3D Plots Using MATLAB Picture 6How to Make 3D Plots Using MATLAB Picture 6
    Define zz in terms of xx and yy because of its reliance on those sets of data.
    1. Use the relationship you know exists between x and y. This is likely to be a function or formula.
    2. e.g., zz=xx.^2-yy.^2
  2. How to Make 3D Plots Using MATLAB Picture 7How to Make 3D Plots Using MATLAB Picture 7
    Plot the surface using the surf command.
    1. From the z components in the matrix "zz", the surf command will create a 3-D shaded surface.
    2. This is the point in which you will relate xx, yy, and zz together.
    3. The actual command line will be in the format of surf(xx,yy,zz) .
  3. How to Make 3D Plots Using MATLAB Picture 8How to Make 3D Plots Using MATLAB Picture 8
    Watch for your new window to appear showing your 3-D plot.
  4. How to Make 3D Plots Using MATLAB Picture 9How to Make 3D Plots Using MATLAB Picture 9
    Customize as you'd like. There is a toolbar at the top of the window where the new plot has appeared. This toolbar contains many options and features that can be used to manipulate your 3-D plot.
    1. Some of these options include:
      1. Inserting a label for the x, y, or z axis
      2. Inserting a legend to help readers
      3. Rotating the plot in it's 3-D space
      4. Inserting a light source to show the effects of shadows
    2. A list of complex surface properties can be found at http://www.mathworks.com/help/matlab/examples/changing-surface-properties.html
  5. How to Make 3D Plots Using MATLAB Picture 10How to Make 3D Plots Using MATLAB Picture 10
    Smooth the color map across the entire surface of the graph, if you'd like. This is done by using the command line shading interp.
4 ★ | 4 Vote