Statements, Expressions, and Variables

MATLAB is an expression language, meaning that the language interprets and evaluates the expressions you type. MATLAB statements are usually of the form

     variable = expression

or simply

     expression

Expressions are usually composed from operators, functions, and variable names. Evaluation of each expression produces a matrix, which is then displayed on the screen and assigned to the variable for future use. If the variable name and the equal sign ( = ) are omitted, a variable ans (for answer) is automatically created, and the result is assigned to it.

A statement is normally terminated with the carriage return. However, a statement can be continued to the next line with three or more periods followed by a carriage return. On the other hand, several statements can be placed on a single line if separated by commas or semicolons.

If the last character of a statement is a semicolon, the printing is suppressed, but the assignment is carried out. This is essential in suppressing unwanted printing of intermediate results.

MATLAB is case-sensitive in the names of commands, functions, and variables. For example, solveUT is not the same as solveut.

The command

 
        who

will list the variables currently in the workspace. You may clear variables from the workspace with the command

 
        clear variablename

The command

 
        clear

alone will clear all nonpermanent variables.

You lose all your variables whenever you log out or exit MATLAB. However, invoking the command

 
        save

before exiting causes all variables to be written to a diskfile named matlab.mat; the next time you reenter MATLAB, issue the command

        load

to restore the workspace to its former state.

You can usually use the CTRL-C key sequence (or CTRL-BREAK on a PC) to stop a runaway display or computation on most machines without leaving MATLAB.

The permanent variable eps (epsilon) gives the machine precision-about 10^(-l6) on most machines. It is useful in determining tolerences for convergence of iterative processes.


Other Matlab Hints

Click on an item listed below to access additional MATLAB-related hints.


Return to ACS home page.


Please send comments and suggestions to

consult@rpi.edu