Some Matlab Basics
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
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.
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
save the notepad file as
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.
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
. That is, a single
variable, say x, is made up of rows and columns. The symbol x(i,j)
represents an element on the
• A number, or
, is a matrix having only a single row and column.
is a matrix having a single row (e.g., x(1,n)).
is a matrix having a single column (e.g., x(n,1)).
A matrix is equivalent to an
in Fortran or C with the number of indices
restricted to two.