Saturday 3 November 2012

1.1 MATLAB BASIC OPERATIONS


When MATLAB is invoked, the command window will display the prompt >>.
MATLAB is then ready for entering data or executing commands. To quit
MATLAB, type the command

exit or quit

MATLAB has on-line help. To see the list of MATLAB’s help facility, type

help


The help command followed by a function name is used to obtain information
on a specific MATLAB function. For example, to obtain information on
the use of fast Fourier transform function, fft, one can type the command

help fft


The basic data object in MATLAB is a rectangular numerical matrix with real
or complex elements. Scalars are thought of as a 1-by-1 matrix. Vectors are
considered as matrices with a row or column. MATLAB has no dimension
statement or type declarations. Storage of data and variables is allocated
automatically once the data and variables are used.

MATLAB statements are normally of the form:

variable = expression


Expressions typed by the user are interpreted and immediately evaluated by the
MATLAB system. If a MATLAB statement ends with a semicolon, MATLAB
evaluates the statement but suppresses the display of the results. MATLAB
is also capable of executing a number of commands that are stored in a file.
This will be discussed in Section 1.6. A matrix


A =
1 2 3
2 3 4
3 4 5






may be entered as follows:


A = [1 2 3; 2 3 4; 3 4 5];
Note that the matrix entries must be surrounded by brackets [ ] with row
elements separated by blanks or by commas. The end of each row, with the
exception of the last row, is indicated by a semicolon. A matrix A can also be
entered across three input lines as


A = [ 1 2 3
2 3 4
3 4 5];

In this case, the carriage returns replace the semicolons. A row vector B with
four elements

B = [ 6 9 12 15 18}
can be entered in MATLAB as
B = [6 9 12 15 18];
or

B = [6 , 9,12,15,18]
For readability, it is better to use spaces rather than commas between the elements.
The row vector B can be turned into a column vector by transposition,
which is obtained by typing
C = B’



The above results in
C =
6
9
12
15
18






Other ways of entering the column vector C are
C = [6
9
12
15
18]


or
C = [6; 9; 12; 15; 18]


MATLAB is case sensitive in naming variables, commands and functions.
Thus b and B are not the same variable. If you do not want MATLAB to be
case sensitive, you can use the command

casesen off


To obtain the size of a specific variable, type size ( ). For example, to find the
size of matrix A, you can execute the following command:

size(A)

The result will be a row vector with two entries. The first is the number of
rows in A, the second the number of columns in A.
To find the list of variables that have been used in a MATLAB session, type
the command
whos
There will be a display of variable names and dimensions. Table 1.1 shows
the display of the variables that have been used so far in this book:








No comments:

Post a Comment