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