Documentation
MATLAB for UNIX
Documentation table of contents.
Introduction
MATLAB, or MATrix LABoratory, is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment. MATLAB's strength is the ease with which it manipulates rectangular arrays of numbers (matrices), relieving the user of explicit dimensioning details.
MATLAB Toolboxes are collections of application-specific functions. The following toolboxes are available: Control System, Communications, Fuzzy Logic, Image Processing, MATLAB Compiler, Neural Network, Optimization, Signal Processing, SIMULINK, Symbolic Match, System Identification, and Wavelet.
Setup
MATLAB is available on UBUnix, and all public Sun workstations. To fully explore MATLAB's interactive graphics ability, you must be using an environment that supports graphical user interface (GUI).
Make sure that you use the default system search path or have included it in your path, and that you use the system MANPATH.
Starting MATLAB
To run MATLAB, enter the following command at your UNIX command prompt:
matlab
Once running, MATLAB will present a pair of greater-than symbols (>>) as its command-line prompt.
File Conventions
MATLAB expects certain file extensions when some commands are executed. Below is a list of file extensions:
| File Contents | Extension |
|---|---|
| MATLAB script file | .m |
| MATLAB binary file | .mat |
MATLAB can read and execute commands from standard input, as well as from
ASCII script files with a .m extension.
These script files are called M-files and can be created with an editor
such as pico, vi, Emacs, or MATLAB's built-in editor. To execute the commands
residing in a file named myproject.m,
enter the filename without the .m extension
at the MATLAB>> prompt:
myproject
You may also execute the file from your UNIX prompt by entering:
matlab < myproject.m > myproject.out
MATLAB executes each command from myproject, then returns you to a prompt. Because MATLAB treats any text following a % symbol as a comment, you can use comments to document your work.
Help in MATLAB
An effective online help facility is available in MATLAB by entering help. MATLAB responds by displaying a list of help topics, along with a brief description of each topic. You can get specific help by entering help with a topic name. For example, entering help plot provides detailed help on MATLAB's 2-D plotting command plot.
To get a quick introduction to MATLAB's features, run the demo program by entering demo.
Command Syntax
MATLAB is case-sensitive. All built-in commands are in lowercase. A command normally terminates with a carriage return. Including a semicolon (;) at the end of a command suppresses MATLAB's echoing to the terminal. (This is useful when dealing with large sets of numbers.)
Matrices
MATLAB works with essentially one kind of object: a matrix of numbers (which could include complex elements). Scalars are 1-by-1 matrices, and vectors are 1-by-n or n-by-1 matrices.
When entering a matrix, separate columns by spaces or commas, and rows
by semicolons. For example, enter:
A = [1 2; 3 4]
This results in:
| A= | ||
| 1 | 2 | |
| 3 | 4 |
MATLAB stores the above 2-by-2 matrix in the variable, A, for later use. To retrieve a variable, simply enter its name (e.g., A).
Matrix and Array Operations
Matrix operations are fundamental to MATLAB and are based on principles of linear algebra. Matrix multiplication, division, power, and transpose are denoted by symbols *, /, ^, and '.
Array operations refer to element-by-element arithmetic operations, rather than the usual linear algebraic operations. Array operations are denoted by preceding an operator with a period (.), such as .*,./ and .^. For addition and subtraction, array and matrix operations are the same.
See the Examples section for a comparison of matrix and array operations.
Saving MATLAB Workspace Variables
Variables created in a MATLAB session can be saved to a file using the
save command:
save myfile
This saves all variables into a file called myfile.mat.
Files with a .mat extension are
in binary format, and are not readable as text. Saved variables can be retrieved
by using the load command:
load myfile
The Colon (:) Notation
The colon (:) is an important notation. It can be used to generate vectors or access submatrices. See Examples in the next section.
Examples
MATLAB's command language is expressive and easy to use. Using MATLAB interactively by entering commands at its >> prompt is an effective way to learn.
The following commands help illustrate some of MATLAB's features:
| Example | Description |
|---|---|
| diary('try') | Saves the text of a MATLAB session into file try (graphics excluded) |
| clear | Clears all variables from memory |
| a = [1 2; 3 4] | Creates a simple 2x2 matrix |
| b = inv(a) | Inverts matrix a and stores it as variable b |
| c = a * b | Matrix multiplication of a and b |
| c = a .* b | Array operation (not the decimal point in the operator) |
| c(:, 2) | The second column of matrix c |
| c(2, :) | The second row of matrix c |
| q = [a b] | Combines matrices a and b, and stores the result as variable q |
| who | Lists the active variables now |
| x = 0: pi/30 : 4*pi | Creates a row vector whose elements range from 0 to 4 pi, in increments of pi/30 |
| x = x' | Takes the transpose of x |
| y = exp (-0.3 * x) .* sin (x) | Creates column vector y as a function of column vector x (note the .* operator) |
| plot(x,y) | Plots the column vectors x and y |
| title('Decaying Sinusoid') | Creates a plot title |
| xlabel('Time (sec)') | Labels the x-axis |
| ylabel('Position (in)') | Labels the y-axis |
| print -dps decay | Creates a PostScript plot file decay.ps |
| clf | Clears the displayed figure |
| [x, y] = meshgrid(-1: 0.05 :1 , -1: 0.1 : 1) | Generates matrices x and y to support 3D surface plotting over the provided intervals |
| size(x) | Displays the dimensions of matrix x |
| z = sin(5 * x .* y); | Creates matrix z, from x and y |
| surf(x,y,z) | Plots the surface z=sin(5xy) |
| view( [20 60] ) | Changes the view and replots (azimuth & elevation) |
| diary off | Turns off diary |
MATLAB Toolboxes
Functions in MATLAB toolboxes can be used in the same way as regular MATLAB
functions. To display all available toolboxes, enter the following from your
MATLAB prompt:
dir $TOOLBOX
To find all functions in a given toolbox, enter:
help toolbox-name
toolbox-name is the name of the
toolbox for which you want help. For example:
help signal
This displays help on the signal toolbox.
Exiting MATLAB
To end your MATLAB session, enter quit from the command prompt.
Additional Information
MATLAB comes with an extensive set of online documentation that can be viewed via a web browser (Internet Explorer, Netscape, etc.). To access it, enter helpdesk at the MATLAB prompt.

