University of Washington, College of Engineering
Electrical Engineering Department
EE235: Continuous Time Linear Systems

Getting Started with MATLAB -- Fall 2001


Getting Started

On a unix system, type matlab at the system prompt. Once it is ready for you, you will see the MATLAB ">>" prompt.

Help and Other Useful Stuff

The general help file can be reached simply by typing help at the prompt. To find out about a specific command, you can type "help ", e.g. "help polyval" or "help plot".

If you want a record of what you have done, then you can use the diary command to send everything on your screen (what you type and what MATLAB spits back) to a file, which you can print out later (i.e. for turning in labs) or email to someone for help when things are going wrong. Type "diary my_file" to turn diary on and specify the file "my_file" for the output to go to. Type "diary off" to turn it off. You can type "help diary" to learn more.

When you type mathematical commands to MATLAB (which includes simply typing numbers), it will print out an answer to the screen unless you explicitly say you want that answer suppressed. When you are first learning to use MATLAB, it is useful to have that answer to be sure that you are using the right command, but when you are working with big arrays this can be unwieldy (and waste space in your "diary"). To suppress the output, just type ";" after your command.

Defining variables

MATLAB works with vectors and matrices defined by a list of numbers using ";" to indicate a new row, as follows: If you have a long vector with a regular structure, you can define it using the ":" notation, e.g. If you want a column vector instead of a row vector, simply define a new variable that is the transpose, e.g. y = x'. Other useful things to know are:

Simple mathematical operations

Let x and y be matrices Operations that you might want to do on scalars include exponentiating (x=exp(y)), taking a log (x=log(y) for natural log, x=log10(y) for base 10 log), and finding sines and cosines (x=cos(y), x=sin(y)).

Plotting

To do a simple x-y plot, you would use the plot command. If you wanted to plot a function f(t) vs. time t, you would first define vector x to contain the time samples (e.g. x=[0:tau:end], where "tau" is the time increment and "end" is the end time of the x-axis) and then define a y vector containing the samples f(k*tau), and then use the command "plot(x,y)". You should always use the commands xlabel, ylabel and title to label the axes of plot that you are going to turn in or put in a paper. If you want a single print-out with multiple subplots on it, use the subplot command. For example, "subplot(m,n,p)" followed by "plot(x,y)" will put your plot in picture with the p-th location (counting left-to-right and top-to-bottom) of an mxn set of plots. Do any plot labeling commands right after you have done the plot command, since they will apply to the most recently done subplot.


This page is maintained by Mari Ostendorf (mo@ee.washington.edu). Last updated on 16 October 00.

Back EE235 Course Information Page