University of Southern California

ITS Information Technology Services

A division of the Office of the Chief Information Officer

Starting MATLAB

Once you have logged into a windowing environment and have sourced the MATLAB setup files, you may start up MATLAB by typing matlab at the UNIX prompt. Once MATLAB has started up, you will see the MATLAB desktop. The desktop consists of 3 windows: Workspace, Command History, and Command Window. The Command Window is where you will see a prompt that looks like >>, and is where you will type in various commands.

matlabdesktop

Basic MATLAB Commands

At the MATLAB prompt, you can run some basic UNIX commands such as cd and ls. For more information on UNIX commands, see the UNIX Documentation Page.

To get general MATLAB help, type help at the prompt to get a list of a help topics. To get help on a specific topic or function, type help at the prompt, replacing with the topic or function you wish to get help on.

To exit MATLAB, type exit or quit at the prompt.

Matlab Basics

MATLAB is designed to work with matrices, where a matrix is defined to be a rectangular array of numbers. All variables used are considered to be matrices. Scalars and vectors can be used since they can be considered as matrices with dimension 1x1 (scalars) and 1xn or nx1 (vectors).

Unlike programming languages such as C or Java, MATLAB does not require any type declarations or dimension statements. When MATLAB encounters a new variable name, it automatically creates the variable and allocates the appropriate amount of storage. If the variable already exists, MATLAB changes its contents and, if necessary, allocates new storage. To check to see what variables already exist and what dimensions they are, type the command whos at the prompt. To clear existing variables from memory enter the command clear at the prompt.

To create a variable, simply type the variable name at the prompt, followed the the equals sign (=), and followed by the initialization, as demonstrated below:

Note: Although not required by MATLAB, linear algebra conventions of naming matrices with capital letters and scalars/vectors with lower case letters is often retained for readability inside MATLAB.

Generating Matrices

MATLAB provides four functions that allow you to easily generate basic matrices.

Matrix Operatons

MATLAB provides several useful matrix operations:

+ Matrix addition
- Matrix subtraction
* Dot product
' Takes the transpose of a matrix
inv Takes the inverse of a matrix
eig Computes the eigenvalues of a square matrix
det Computes the determinant of a matrix
rref Calculates the reduced row echelon form of a matrix

Using M-Files


MATLAB allows you to write scripts and define functions in external files called M-Files. M-Files have the file extension .m, and can be executed at the MATLAB prompt by simplying typing in the filename without the .m extension. To create a new M-File:

MATLAB Toolboxes

At USC, the following MATLAB toolboxes are available:

To access a Toolbox, go to the MATLAB Start menu, then go to the Toolboxes submenu, then select the Toolbox you wish to use.

startmenu.jpg

Getting Help With MATLAB

To get general MATLAB help, type help at the MATLAB command prompt to get a list of a help topics. To get help on a specific topic or function, type help at the prompt, replacing with the topic or function you wish to get help on.

MathWorks provides extensive MATLAB documentation online. To access this documentation, go to MATLAB Getting Started

If you have questions regarding this documentation, or are having trouble logging into your account and sourcing the MATLAB setup files, please contact the Customer Support Center at 213-740-5555 or email consult@usc.edu.

Last updated:
February 04, 2011

MATLAB

The use of all USC computing resources is governed by the USC Computing Policies.