This preview shows pages 1–3. Sign up to view the full content.
MIT OpenCourseWare
http://ocw.mit.edu
2.672 Project Laboratory
Spring 2009
For information about citing these materials or our Terms of Use, visit:
http://ocw.mit.edu/terms
.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentMATLAB FOR 2.672
This is a short introduction to the MATLAB software. The idea is to enable you to use MATLAB quickly.
Refer to the MATLAB REFERENCE MANUAL for more sophisticated operations.
TO USE MATLAB

click the MATLAB icon.
It will set up your directory as default for you so that you can
access your files.
CONCEPTS
o
MATLAB is a giant calculator which remembers the values of all the variables you have calculated.

The command you type in is executed every time you hit a carriage return (CR). Use the
upanddown
arrow keys to recall previous commands
.

Sometimes you
do not want the intermediate results
to be printed (e.g., when you are calculating the
values of a thousand numbers). To do this,
end the command with semicolon,
before the CR.

For a very long command that you cannot finish in one line, the line can be continued to the next by using
the ellipsis consisting of
three dots.
..
, before the CR.
o
One can store a set of commands in a script file and recall it to be used. More of this later in the section
SCRIPT FILES
. (Using a script file is preferred if you have to do any serious calculations because then
you have a record of all the commands you put in, and you can edit them and redo the command sequence
easily.)
o
If you want to clear your "calculator," use the command
CLEAR
. You can clear a specific variable by
CLEAR variable_name
.
o
Variables in MATLAB are case sensitive!!!
If you prefer, you could adapt the convention of using lower
case characters for scalars and uppercase characters for vectors and matrices.
o
MATLAB stands for MATRIX LABORATORY; therefore, the basic representation of information is in
terms of matrices. A number, or scalar, is a 1x1 matrix. In 2.672, we mostly deal with vectors (e.g., an
array of data).
Because the software is matrixbased, there can be quite a bit of confusion if you are not
careful. For example, if x is a 5x1 matrix (i.e., a column vector of 5 elements),
X*X
is illegal. On the other
hand
X*X'
(
X'
stands for the transpose of X) will give you a scalar.
o
You can always click the
HELP
icon to search for information within MATLAB.
BASIC OPERATIONS
o The
operators +,,*,/,^
have the usual meaning.
(The last one is to raise power.)
 operation between a scalar (s) and a matrix (A) is straight forward; e.g. s*A means that every element of A
is multiply by s.
 For operations between matrices (vectors are special case of matrices: a row vector of n elements is a nx1
matrix; a column vector is a 1xn matrix), you have to be careful that the dimensions match, or you will get
error messages.
 Division means multiplication by the inverse matrix. As such, there are two different symbols: the right
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '09
 DouglasHart

Click to edit the document details