Upload
sahil-ahuja
View
219
Download
0
Embed Size (px)
Citation preview
8/13/2019 Instruction for MATLAB
1/2
Instructions for using MATLAB
1. For lunching MATLAB, double click on the program icon, which is available on the
window desktop.
2.MATLAB put ou in command window a!ter lunching it. "ommand window is the
main window. #t is characteri$ed b MATLAB prompt %>>&. All commands, includingthose !or running user written programs, are tped in this window at the MATLAB
prompt. '(cept command window, MATLAB also have two separate windows. These
are)
Edit-window:This is where ou write, edit, create, and save our own programs in !ile
called %M*!ile& or .m!ile.
Graphic window or Figure window:The output o! all graphics commands tped in the
command window are !lushed to the graphics orFigure window.
+. Creating, Saving and Executing a Script Fie! .m fie"
A script !ile is a user created !ile with a seuence o! MATLAB command in it. The !ile
must be saved with a %.m& e(tension to its name, therb, making it an M*!ile. A script !ile
is e(ecuted b tping its name -without the %.m& e(tension at the command prompt.
Steps for creating a new .m file
-i /elect #e$ M%Fie !rom the Fiemenu. A new edit window should appear.
-ii 0rit the MATLAB commands in the edit window. An line starting with sign are
interpreted as comment line b MATLAB and are ignored.
-iii /elect Save& Save As!rom Fie menu. A dialog bo( should appear. Tpe the name o!
the document with e(tension o! .m and click Save. The document now saved in thecurrent working !older.
.Execution of a Script File)
A /cript !ile is e(ecuted b tping the name o! the !ile -without the %.m& e(tension. #t is
euivalent to tping all the commands stored in the script !ile, one b one, at the
MATLAB prompt. 3aturall, script !iles work on global variables, that is, variables
currentl present the workspace. 4esults obtained !rom e(ecuting script !iles are le!t in
the workspace.
#! a MATLAB command is !inishes without a semicolon -5, then the result o! the
command will be displaed in the screen when we e(ecute the script !ile.
Caution:
6 3ever name a script !ile the same as the name o! a variable it computes. 0hen
MATLAB looks !or a name, it !irst searches the list o! variables in the workspace. #! a
variable o! the same name as the script !ile e(ist, MATLAB will never be able to access
the script !ile.
8/13/2019 Instruction for MATLAB
2/2
6 The name o! a script !ile must be begins with a letter. The rest o! the character ma
include digits and underscore character. 7ou ma not use an periods -. in the name
other than the last one in %.m&.
6 Avoid name clashes with built*in*!unctions. #t good idea to !irst check i! a !unction or
script o! the proposed name alread e(ists. 7ou can do this with the command exist-%!ilename&, which returns $ero i! nothing with namefilenamee(ist.
8.How to create MA!A" Function:
A !unction !ile created !or developing a MATLAB !unction. A !unction !ile is also an
%.m& !ile, e(cept that the variables in a !unction !ile are all local. Function !iles like
programs or subroutines in ".
A !unction !ile begins with a !unction de!inition line, which has a well*de!ined list i!
inputs and outputs. 0ithout this line, the !ile becomes a script !ile. The snta( o! the
!unction de!inition line is as !ollows)
function#output $aria%les& ' function(name)input $aria%les*
0here the !unction*name must be same as the !ilename -without the .m e(tension in
which the !unction is written.
Caution:The !irst word in the !unction de!inition line, !unction, must be tped in lower
case. A common mistake to is tpe it as Function.
More details about this re!er 9:etting started with MATLAB 8, b 4udra ;ratap, "h*.2ust cop them to the work !older and use it.
#! the !iles are not removed !rom the work !older then the !iles are compulsoril deleted
be!ore start o! the ne(t Lab*"lass.
?. @eep a hard cop o! all our script !iles and output result o! ever MATLAB e(ercises
that given to ou during our Lab*"lass.
. Attach the hard copies o! our script !ile and output result in our Lab*4ecord and
submit it in ever Lab*"lass !or signature.
. Be!ore leaving the terminal, properl close the MATLAB window.