Matlab Notes:
Some Matlab Basics
2
ME563 - cmk
Some Matlab Basics
The following are some basic things about Matlab that you will need to know
before using the application. The list is by no means complete. You will
continually learn new things every time that you use Matlab.
(a) Command window
The Command window is the window that first
appears when you first get onto Matlab. This is the window within which
you will be doing all your Matlab operations. Think of this window as
being a calculator, a calculator that will allow you do perform simple
arithmetic
operations,
scientific
calculations,
plotting,
exporting/
importing data to/from M-files, etc.
(b) Script files (M-files)
If the amount of instructions given to Matlab become
long and involved and will be perform repeatedly, you will find it
convenient to place your instructions in a script file (known as an M-file)
that can be executed as a program.
• To
create
a new M-file
, open a new file with the Notepad editor. Within
the Notepad window, type your Matlab commands and the save the
file. Be sure to save the file with a “.m” suffix (known as an
“extension”) so that Matlab will be able to recognize it as an M-file.
For example, if you want the name of your program to be
main
, then
save the notepad file as
main.m
.
• To
modify an existing M-file
, use the Notepad editor. Within the
Notepad window, make the desired changes to the file. Be sure to
save this file before leaving the Notepad window.
• To
run an existing M-file
, simply type the name of the M-file (without
the “.m” extension) while in the Command window.
(c) Matlab variables
All variables in Matlab are
matrices
1
. That is, a single
variable, say x, is made up of rows and columns. The symbol x(i,j)
represents an element on the
ith row
and
jth column
of x.
• A number, or
scalar
, is a matrix having only a single row and column.
• A
row vector
is a matrix having a single row (e.g., x(1,n)).
• A
column vector
is a matrix having a single column (e.g., x(n,1)).
1
A matrix is equivalent to an
array
in Fortran or C with the number of indices
restricted to two.