MATLAB 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.
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
arrow keys to recall previous commands
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 semi-colon,
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
, before the CR.
One can store a set of commands in a script file and recall it to be used. More of this later in the section
. (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
If you want to clear your "calculator," use the command
. You can clear a specific variable by
Variables in MATLAB are case sensitive!!!
If you prefer, you could adapt the convention of using lower-
case characters for scalars and upper-case characters for vectors and matrices.
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 matrix-based, 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),
is illegal. On the other
stands for the transpose of X) will give you a scalar.
You can always click the
icon to search for information within MATLAB.
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
- Division means multiplication by the inverse matrix. As such, there are two different symbols: the right