lecture 01: getting started - nc state universityscroggs/ma591matlab/lecturenotes/l01.pdf ·...
TRANSCRIPT
Lecture01:GettingStarted
Goal:startusingMatlabasquicklyaspossible
Goal:understandthewaythecourseisrun
8/19/10 1IntrMatlabforFM,Fall2010
Today
1. StartMatlab2. Touroftheinterface3. Rundemo
4. UseMatlabasacalculator5. Scriptfiles6. Functionfiles
8/19/10 2IntrMatlabforFM,Fall2010
StartingMatlab1.ChooseAdminLauncher2.ClickonStartMATAB
1
2
8/19/10 3IntrMatlabforFM,Fall2010
MatlabEnvironment
8/19/10 4IntrMatlabforFM,Fall2010
MATLABopenstoadefaultwindowconfiguration
8/19/10 5IntrMatlabforFM,Fall2010
• MATLABusesastandardwindowsmenubar
• ToexitMATLABusethecloseicon
8/19/10 6IntrMatlabforFM,Fall2010
Command Window Enter commands at the prompt Current Directory
MATLABWindowsCommand History
Workspace Window
8/19/10 7IntrMatlabforFM,Fall2010
8/19/10 IntrMatlabforFM,Fall2010 8
Windows
1. Command2. CommandHistory
3. Workspace
4. CurrentDirectory5. Editor6. Figure
8/19/10 9IntrMatlabforFM,Fall2010
Youcanusethecommandwindowmuchlikeyou’duseacalculator
Thestandardorderofoperationrulesapply
8/19/10 10IntrMatlabforFM,Fall2010
• Similartoascratchpad• Onceyouhitenter,youcan’teditanycommands
• Youcanretypethemorusethearrowkeystoretrievecommandsandeditthembeforehittingenteragain
CommandWindow
8/19/10 11IntrMatlabforFM,Fall2010
CommandHistory
• Recordsthecommandsyouissueinthecommandwindow
• Whenyouexitthecommandwindow,orwhenyouissuetheclccommand,thecommandwindowiscleared
• Butthecommandhistoryremains
CommandHistory
8/19/10 12IntrMatlabforFM,Fall2010
CommandHistory
• Youcantransfercommandsfromthecommandhistorytothecommandwindow– Doubleclickonacommand– Clickanddrag
8/19/10 13IntrMatlabforFM,Fall2010
RepeatthesecalculationsbydraggingthemfromtheCommandHistory
1. squarerootof652. sin(31)3. (55+17)/3
8/19/10 14IntrMatlabforFM,Fall2010
WorkspaceWindow
• Keepstrackofthevariablesyou’vedefined– Name– Value– Class– Size– Bytes
• Youmayneedtoclickonthenamebarandselectsizeandbytesinordertoseetheseparameters
WorkspaceWindow
8/19/10 15IntrMatlabforFM,Fall2010
8/19/10 16IntrMatlabforFM,Fall2010
Whenyoudefinevariablesinthecommandwindow,theyarelistedintheworkspacewindow
8/19/10 17IntrMatlabforFM,Fall2010
Definethefollowingvariables
Aisthevalueofthesquarerootof65Bisthevalueofsin(31)
Cisthevalueof(55+17)/3
8/19/10 18IntrMatlabforFM,Fall2010
DocumentWindow
• IfyoudoubleclickonanyvariableintheworkspacewindowMATLABlaunchesadocumentwindowcontainingthearrayeditor
• Youcaneditvariablesinthearrayeditor
8/19/10 19IntrMatlabforFM,Fall2010
DocumentWindow
8/19/10 20IntrMatlabforFM,Fall2010
CurrentDirectoryWindow
• Aviewofthefilesandfoldersofthecurrentworkingdirectory
8/19/10 21IntrMatlabforFM,Fall2010
CurrentDirectory
• Thecurrentdirectorywindowisalistoffiles
• Whenyoutrytoloadinformationfromafileortrytosaveinformation–MATLABusesthecurrentdirectory
8/19/10 22IntrMatlabforFM,Fall2010
FigureWindow
• WhenFiguresarecreatedanewwindowopens
• It’sextremelyeasytocreategraphsinMATLAB
8/19/10 23IntrMatlabforFM,Fall2010
Thesemicolonsuppressestheoutputfromeachcommand
8/19/10 24IntrMatlabforFM,Fall2010
8/19/10 25IntrMatlabforFM,Fall2010
EditingWindow
• Thiswindowallowsyoutotypeandsaveaseriesofcommandswithoutexecutingthem
• Thereareseveralwaystoopenaneditingwindow– Fromthefilemenu
– Withthenewfileicon
8/19/10 26IntrMatlabforFM,Fall2010
Openaneditingwindowfromthefilemenuorwiththenewfileicon
8/19/10 27IntrMatlabforFM,Fall2010
SaveandRun
Writeyourcodeintheeditingwindow,thenrunitusingtheSaveandRunicon
8/19/10 28IntrMatlabforFM,Fall2010
OrganizeFolders&RunDemo
• Keepalltheworkforasingleassignmentinitsownfolder
• Everybodyshouldhaveacopyoffolderncm
• Donotworkinfolderncm
• Makenochangestofilesinfolderncm
• Createfoldertemp0fortoday’swork
8/19/10 IntrMatlabforFM,Fall2010 29
OrganizeFolders&RunDemoCreatefoldertemp0andsetupto
workinit
8/19/10 IntrMatlabforFM,Fall2010 30
1. Clickonellipses
2.createfoldertemp0
OrganizeFolders&RunDemoCreatefoldertemp0andsetupto
workinit
8/19/10 IntrMatlabforFM,Fall2010 31
Note:foldertemp0isatthesamelevelasfolderncm
Forthisclassallworkingfolderswillbeatthesamelevelasfoldertemp0
OrganizeFolders&RunDemoCreatefoldertemp0andsetupto
workinit
8/19/10 IntrMatlabforFM,Fall2010 32
OrganizeFolders&RunDemoCreatefoldertemp0andsetupto
workinit
8/19/10 IntrMatlabforFM,Fall2010 33
Whatyouneedduringclass1. Laptopcomputer2. withMatlabinstalled3. thathasabrowserinterfacingwiththe
website
TheNCSUlaptopsmeettheseconditions
Ifyoubringyourownlaptop,yourMatlabinterfacemaybedifferent.
8/19/10 34IntrMatlabforFM,Fall2010
Beforeclassstarts1. Startyourlaptop2. StartMatlab3. Movetothecurrentworkingdirectory4. Setthepathsothesamplefileswillexecute
DuringClass1. Followalongusingyourlaptop2. Interactwithyourfellowstudents3. Askquestionsoftheinstructor4. Whenitgetstooloud
8/19/10 35IntrMatlabforFM,Fall2010
ScriptFilesandFunctions
Classexercise–createandtestscriptfilep3.m
• Runthecommandsonpages3and4ofthetextbookintheCommandWindow
• Openfilep3.mwiththeeditor• CopythecommandsfromtheCommandHistoryWindowtofilep3.m
• Runthescriptfilep3.m
Workwiththepeoplearoundyoutoaccomplishthis
Comments
• Besuretocommentyourcodesoweknowwhatishappening.
• Best:usemeaningfulvariablenames
The % sign starts the comments
nexttime:control‐flow
1. IF‐THEN‐ELSEIF‐ELSE2. FOR‐END3. WHILE‐END4. SWITCH‐CASE
8/19/10 38IntrMatlabforFM,Fall2010