Lecture note Data visualization - Chapter 26
Số trang: 12
Loại file: pptx
Dung lượng: 139.86 KB
Lượt xem: 9
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
This chapter presents the following content: Basic definitions, example of a database, typical DBMS functionality, main characteristics of the database approach, database users, workers behind the scene,...
Nội dung trích xuất từ tài liệu:
Lecture note Data visualization - Chapter 26Lecture26RecapSavingPlotsSummaryofChapter5IntroductionofChapter6FunctionMfilesUserdefinedfunctionsarestoredasMfilesandcanbe accessedbyMATLABiftheyareinthecurrentfolderor onMATLAB’ssearchpathSyntaxofFunctionMfileBothbuiltinMATLAB®functionsanduserdefined MATLABfunctionshavethesamestructureEachconsistsofaname,userprovidedinput,and calculatedoutput.Forexample:thefunction cos(x) isnamedcos takestheuserinputinsidetheparentheses(inthiscase,x) calculatesaresultContinued….UserdefinedfunctionsarecreatedinMfiles.Eachmust startwithafunctiondefinitionlinethatcontains: Thewordfunction Avariablethatdefinesthefunctionoutput Afunctionname AvariableusedfortheinputargumentForexample: functionoutput=my_function(x)isthefirstlineoftheuserdefinedfunctioncalledmy_functionContinued….Here’sanexampleofaverysimpleMATLABfunction thatcalculatesthevalueofaparticularpolynomial: functionoutput=poly(x) %Thisfunctioncalculatesthevalueofathirdorder %polynomial output=3*x.^3+5*x.^22*x+1;Thefunctionnameispoly,theinputargumentisx,and theoutputvariableisnamedoutputBeforethisfunctioncanbeused,itmustbesavedintothe currentfolderContinued….OncetheMfilehasbeensaved,thefunctionisavailable forusefromthecommandwindow,fromascriptMfile, orfromanotherfunctionYoucannotexecuteafunctionMfiledirectlyfromthe Mfileitself.Thismakessense,sincetheinputparameters havenotbeendefineduntilyoucallthefunctionfromthe commandwindoworascriptMfileConsiderthepolyfunctionjustcreated.If,inthe commandwindow,wetype poly(4)thenMATLABrespondswith ans=265CommentsAswithanycomputerprogram,codeshouldbe commentedliberallysothatitiseasytofollowHowever,inaMATLABfunction,thecommentsonthe lineimmediatelyfollowingtheveryfirstlineservea specialroleTheselinesarereturnedwhenthehelpfunctionisqueried fromthecommandwindow Consider,forexample,thefollowingfunction: functionresults=f(x) %Thisfunctionconvertssecondstominutes FunctionswithMultipleInputsandOutputsContinued….Similarly,auserdefinedfunctioncouldbewrittento multiplytwovectorstogether: functionoutput=g(x,y) %Thisfunctionmultipliesxandytogether %xandymustbethesamesizematrices a=x.*y; output=a;Whenxandyaredefinedinthecommandwindowand thefunctiongiscalled,avectorofoutputvaluesis returned: x=1:5;Continued….Suchfunctionscanalsobecreatedthatreturnmorethan oneoutputvariableManyofthepredefinedMATLABfunctionsreturnmore thanoneresultForexample:maxreturnsboththemaximumvalueina matrixandtheelementnumberatwhichthemaximum occurs.Toachievethesameresultinauserdefined function,maketheoutputamatrixofanswersinsteadofa singlevariable,asin function[dist,vel,accel]=motion(t) %Thisfunctioncalculatesthedistance,velocity,andContinued….Remember,allvariablesinMATLABarematrices,soit’s importantintheprecedingexampletousethe.*operator, whichspecifieselementbyelementmultiplicationForexample:usingavectoroftimevaluesfrom0to30 inthemotionfunction time=0:10:30; [distance,velocity,acceleration]=motion(time) returnsthreevectorsofanswers: distance=083.33666.672250.00 velocity=025.00100.00225.00 acceleration=05.0010.0015.00
Nội dung trích xuất từ tài liệu:
Lecture note Data visualization - Chapter 26Lecture26RecapSavingPlotsSummaryofChapter5IntroductionofChapter6FunctionMfilesUserdefinedfunctionsarestoredasMfilesandcanbe accessedbyMATLABiftheyareinthecurrentfolderor onMATLAB’ssearchpathSyntaxofFunctionMfileBothbuiltinMATLAB®functionsanduserdefined MATLABfunctionshavethesamestructureEachconsistsofaname,userprovidedinput,and calculatedoutput.Forexample:thefunction cos(x) isnamedcos takestheuserinputinsidetheparentheses(inthiscase,x) calculatesaresultContinued….UserdefinedfunctionsarecreatedinMfiles.Eachmust startwithafunctiondefinitionlinethatcontains: Thewordfunction Avariablethatdefinesthefunctionoutput Afunctionname AvariableusedfortheinputargumentForexample: functionoutput=my_function(x)isthefirstlineoftheuserdefinedfunctioncalledmy_functionContinued….Here’sanexampleofaverysimpleMATLABfunction thatcalculatesthevalueofaparticularpolynomial: functionoutput=poly(x) %Thisfunctioncalculatesthevalueofathirdorder %polynomial output=3*x.^3+5*x.^22*x+1;Thefunctionnameispoly,theinputargumentisx,and theoutputvariableisnamedoutputBeforethisfunctioncanbeused,itmustbesavedintothe currentfolderContinued….OncetheMfilehasbeensaved,thefunctionisavailable forusefromthecommandwindow,fromascriptMfile, orfromanotherfunctionYoucannotexecuteafunctionMfiledirectlyfromthe Mfileitself.Thismakessense,sincetheinputparameters havenotbeendefineduntilyoucallthefunctionfromthe commandwindoworascriptMfileConsiderthepolyfunctionjustcreated.If,inthe commandwindow,wetype poly(4)thenMATLABrespondswith ans=265CommentsAswithanycomputerprogram,codeshouldbe commentedliberallysothatitiseasytofollowHowever,inaMATLABfunction,thecommentsonthe lineimmediatelyfollowingtheveryfirstlineservea specialroleTheselinesarereturnedwhenthehelpfunctionisqueried fromthecommandwindow Consider,forexample,thefollowingfunction: functionresults=f(x) %Thisfunctionconvertssecondstominutes FunctionswithMultipleInputsandOutputsContinued….Similarly,auserdefinedfunctioncouldbewrittento multiplytwovectorstogether: functionoutput=g(x,y) %Thisfunctionmultipliesxandytogether %xandymustbethesamesizematrices a=x.*y; output=a;Whenxandyaredefinedinthecommandwindowand thefunctiongiscalled,avectorofoutputvaluesis returned: x=1:5;Continued….Suchfunctionscanalsobecreatedthatreturnmorethan oneoutputvariableManyofthepredefinedMATLABfunctionsreturnmore thanoneresultForexample:maxreturnsboththemaximumvalueina matrixandtheelementnumberatwhichthemaximum occurs.Toachievethesameresultinauserdefined function,maketheoutputamatrixofanswersinsteadofa singlevariable,asin function[dist,vel,accel]=motion(t) %Thisfunctioncalculatesthedistance,velocity,andContinued….Remember,allvariablesinMATLABarematrices,soit’s importantintheprecedingexampletousethe.*operator, whichspecifieselementbyelementmultiplicationForexample:usingavectoroftimevaluesfrom0to30 inthemotionfunction time=0:10:30; [distance,velocity,acceleration]=motion(time) returnsthreevectorsofanswers: distance=083.33666.672250.00 velocity=025.00100.00225.00 acceleration=05.0010.0015.00
Tìm kiếm theo từ khóa liên quan:
Data visualization Lecture note Data visualization Data structures Data Visualization with C Data visualization with matlab Effective graphical displayGợi ý tài liệu liên quan:
-
Trực quan hóa dữ liệu: Vai trò & thử thách
10 trang 35 0 0 -
Ebook Management support systems: Part 2 - Dr. Kamlesh Lakhwani
136 trang 30 0 0 -
Ebook Eloquent JavaScript - A modern introduction to programming: Part 1
199 trang 30 0 0 -
Lecture Introduction to computing systems (2/e): Chapter 19 - Yale N. Patt, Sanjay J. Patel
28 trang 26 0 0 -
Ebook Introduction to algorithms (3rd edition)
1313 trang 24 0 0 -
Lecture Data structures and algorithms: Chapter 1 - Introduction
41 trang 24 0 0 -
335 trang 21 0 0
-
169 trang 21 0 0
-
Lecture Data Structures: Lesson 41
18 trang 20 0 0 -
Lecture Data Structures: Lesson 38
71 trang 19 0 0