





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This matlab tutorial provides an overview of matlab, its functionality, and how to obtain and use it. Learn about matrices, data types, built-in functions, and user-defined functions. Discover alternatives to matlab, and explore the use of matrices, accessing individual elements, finding the size of variables, and determining variables in the workspace. This tutorial also covers creating figures, plotting continuous and discrete-time signals, labeling plots, creating multiple graphs, and saving and loading data.
Typology: Lab Reports
1 / 29
This page cannot be seen from the preview
Don't miss anything!






















-^
second floor of ESB
-^
www.mathworks.com – Student version available for $99– Need the Control Systems Toolbox ($29)
Accessing Individual Elements of a Variable
-^
row
col
returns a value of
-^
-^
column
returns all rows in the second column
MATLAB inherently works with matrices•^
All operations default to matrix operations
-^
Let
A = [ 1 2 3; 4 5 6];
-^
Let
B = [1; 1; 1];
-^
C = A*B^ –
Returns
6; 15
-^
If you tell MATLAB to multiply, it assumes you mean matrixmultiplication
-^
The
’
mark performs the transpose of the matrix
-^
Ex.
A’
returns
1 4; 2 5; 3 6
For element-by-element operation (multiplication, division,
exponentiation, etc.)
-^
Use the “.” operator – Put a. before the operator
-^
Ex.
tt_squared = tt.*tt;
-^
This also works with division (
/) and exponentiation (
^)
-^
-^
-^
-^
Create a legend for all the traces on the plot^ –
legend('Signal 1', 'Signal 2')
-^
Change the axes ranges to display only the range youdesire^ – axis([low_x high_x low_y high_y])^ –
Ex.
axis([-10 10 0 5]);
Turn the grid on or off^ – grid
Toggles the grid on or off
Turns the grid on
Turns the grid off
Hold the plot to allow another signal to be plotted on thesame plot^ – hold
Toggles the hold function
Turns the hold function on
Turns the hold function off
Plots can be printed directly from the figure window
-^
Plots can also be saved in a variety of formats^ –
.fig files
-^
.fig files are the default from the pull-down menu
-^
.fig files can only be reopened in MATLAB
-^
Metafile for use in Word documents and PowerPoint slides^ •
Copies the figure to the clipboard • print –dmeta
-^
.eps files^ •
E
ncapsulated P
ost S
cript files
-^
Vectorized images
-^
For use in LaTeX files
-^
Called file_name.eps
You are able to save all of your data in the workspace using
the
save
function
Ex.
save ee327_example A tt
Creates a file called
ee327_example.mat
You can later load these variables by using the
load
function
Ex.
load ee327_example
will load all variables
contained in the .mat file (
and
tt
This command will replace any existing variables of thesame name that are already in the workspace
Instead of entering everything at the command line, you can
write scripts (.m files) to allow you to save your steps Uses the same syntax as the command line•^
To create a new script, type
edit
at the command line
To edit an existing script, type edit filename The
symbol comments everything following it on the line