MATLAB Programming/Graphics

Plot
The plot command renders a 2D line in Cartesian coordinates.

Example:

Matlab also lets the user specify the line style. The following example generates the same graph as in the previous example, but plots the function with a specific line style: a black line with circle markers on each node:

To plot two or more graphs in one figure, simply append the second (x,y) pair to the first: The following example will plot y1 and y2 on the same x-axis in the output.

Polar Plot
Plots a function using θ and r(θ)

plot3
The "plot3" command is very helpful and makes it easy to see three-dimensional images. It follows the same syntax as the "plot" command. If you search the MATLAB help (not at the command prompt. Go to the HELP tab at the top of the main bar and then type plot3 in the search), you will find all the instruction you need.

Example:

This example plots a line in 3D. I created this code in an M-file. If you do the same, change the values and hit the run button in the menu bar to see the effect.

Mesh
Creates a 3D plot using vectors x and y, and a matrix z. If x is n elements long, and y is m elements long, z must be an m by n matrix.

Example:

Contour
Creates a 2D plot of a 3D projection, using vectors x and y, and a matrix z. If x is n elements long, and y is m elements long, z must be an m by n matrix.

Example:

Contourf
Same as contour, but fills color between contour lines

Surface
Basically the same as mesh