Stat/Math
Software Support
Software Consulting
Software Availability
Software Price
Contact

User Support
Documentation
Knowledge Base
Education
Consulting
Podcasts

Systems & Services
Cyberinfrastructure
Supercomputers
Grid Computing
Storage
Visualization
Digital Libraries & Data

Results & Impact
Publications
Grants & Grant Info
Events & Outreach
Economic Impact
Survey Results

Vision & Planning
News & Features

# Plotting with Matlab

All Matlab variables must have numerical values:

>> x = -10:.1:10;

The basic plot command:

>> plot(sin(x))

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

>> plot( x, sin(x) )

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, ...):

>> plot( x, cos(x), x, 1 - x.^2./2, x, 1 - x.^2./2 + x.^4./24 )

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

>> plot( x, exp(x) ), set(gca,'yscale','log')

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!

>> [x y] = meshgrid(-3:.1:3, -3:.1:3);
>> z = x.^2 - y.^2;

Here are two options for plotting the surface. Look at the help page for details.