Plotting with Matlab
All Matlab variables must have numerical values:
The basic plot command:

Note that the horizontal axis is marked according to the index, not the value of x. Fix this as follows:

This is the same thing as plotting "parametric curves."
| We can plot the "inverse relationship" (for example, the squaring function and +/- square root) easily: | |
| >> plot( x, x.^2 ) | >> plot( x.^2, x ) |
![]() |
![]() |
| or a spiral in two or in three dimensions: | |
| >> t = 0:.1:10; plot( t .* cos(t), t .* sin(t) ) | >> plot3( t .* cos(t), t .* sin(t), t ) |
![]() |
![]() |
Plot several curves simultaneously with plot(x1, y1, x2, y2, ...):

Let's add some options [first plot, then options] -- the order of the options can affect the result!
We will first make the scales [the "ratio"] equal, then set the plotting window to be -6 < x < 6, -2 < y < 2.

Here's another example, a semilog plot. In the graphic we also have introduced another variation, the "plot matrix" -- to learn more, enter the command help subplot

Here are other ways to graph multiple curves, using matrices (plotted by columns) and using "hold."
![]() |
![]() |
Functions of two variables may be plotted, as well, but some "setup" is required!
>> z = x.^2 - y.^2;
Here are two options for plotting the surface. Look at the help page for details.









