Lecture note Data visualization - Chapter 27
Số trang: 34
Loại file: pptx
Dung lượng: 2.84 MB
Lượt xem: 13
Lượt tải: 0
Xem trước 4 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
The main contents of the chapter consist of the following: Function M-files, syntax of function M-Files, comments, multiple input and output functions, relational model concepts, relational model constraints and relational database schemas, update operations and dealing with constraint violations.
Nội dung trích xuất từ tài liệu:
Lecture note Data visualization - Chapter 27Lecture27RecapFunctionMfilesSyntaxofFunctionMFilesCommentsMultipleInputandOutputFunctionsFunctionswithNoInputorNoOutputAlthoughmostfunctionsneedatleastoneinputand returnatleastoneoutputvalue,insomesituationsno inputsoroutputsarerequiredForexample:considerthisfunction,whichdrawsastar inpolarcoordinates: function[]=star() theta=pi/2:0.8*pi:4.8*pi; r=ones(1,6); polar(theta,r)ThesquarebracketsonthefirstlineindicatethattheContinued….TherearenumerousbuiltinMATLABfunctionsthatdo notrequireanyinput.Forexample: A=clock returnsthecurrenttime: A= 1.0e+003* Columns1through4 2.0050 0.0030 0.0200 0.0150 Columns5through6DeterminingtheNumberofInputandOutputArgumentsTheremaybetimeswhenyouwanttoknowthenumber ofinputargumentsoroutputvaluesassociatedwitha functionMATLABprovidestwobuiltinfunctionsforthispurposeThenarginfunctiondeterminesthenumberofinput argumentsineitherauserdefinedfunctionorabuiltin functionThenameofthefunctionmustbespecifiedasastring,as, forexample:in nargin(sin)Continued….Whennarginisusedinsideauserdefinedfunction,it determineshowmanyinputargumentswereactually enteredThisallowsafunctiontohaveavariablenumberofinputsRecallgraphingfunctionssuchassurfWhensurfhasasinglematrixinput,agraphiscreated, usingthematrixindexnumbersasthex–andy coordinates.Whentherearethreeinputs,x,y,andz, thegraphisbasedonthespecifiedxandy–valuesThenarginfunctionallowstheprogrammertodetermineContinued….Thesurffunctionisanexampleofafunctionwitha variablenumberofinputsIfweusenarginfromthecommandwindowtodetermine thenumberofdeclaredinputs,thereisn’tonecorrect answerThenarginfunctionreturnsanegativenumbertoletus knowthatavariablenumberofinputsarepossible: nargin(surf) ans=1Thenargoutfunctionissimilartonargin,butit determinesthenumberofoutputsfromafunction:Continued….Anexampleofafunctionwithmultipleoutputsismax: nargout(max) ans=2Whenusedinsideauserdefinedfunction,nargout determineshowmanyoutputshavebeenrequestedbythe userConsiderthisexample,inwhichwehaverewrittenthe functiontocreateastar: functionA=star1() theta=pi/2:0.8*pi:4.8*pi; r=ones(1,6);LocalVariablesThevariablesusedinfunctionMfilesareknownaslocal variablesTheonlywayafunctioncancommunicatewiththe workspaceisthroughinputargumentsandtheoutputit returnsAnyvariablesdefinedwithinthefunctionexistonlyfor thefunctiontouseForexample:considerthegfunctionpreviously described: functionoutput=g(x,y) %ThisfunctionmultipliesxandytogetherContinued….Justascalculationsperformedinthecommandwindowor fromascriptMfilecannotaccessvariablesdefinedin functions,functionscannotaccessthevariablesdefinedin theworkspaceThismeansthatfunctionsmustbecompletelyself contained:Theonlywaytheycangetinformationfrom yourprogramisthroughtheinputarguments,andtheonly waytheycandeliverinformationisthroughthefunction outputConsiderafunctionwrittentofindthedistanceanobject fallsduetogravity: functionresult=distance(t)Continued….ThevalueofgmustbeincludedinsidethefunctionItdoesn’tmatterwhetherghasorhasnotbeenusedinthe mainprogramHowgisdefinedishiddentothedistancefunctionunless gisspecifiedinsidethefunctionOfcourse,youcouldalsopassthevalueofgtothe functionasaninputargument: functionresult=distance(g,t) %Thisfunctioncalculatesthedistanceafallingobject GlobalVariablesUnlikelocalvariables,globalvariablesareavailabletoall partsofacomputerprogramIngeneral,itisabadideatodefineglobalvariablesHowever,MATLABprotectsusersfromunintentionally usingaglobalvariablebyrequiringthatitbeidentified bothinthecommandwindowenvironmentandinthe functionthatwilluseitConsiderthedistancefunctiononceagain: functionresult=distance(t) %ThisfunctioncalculatesthedistanceafallingobjectCreatingToolBoxofFunctionsWhenafunctioniscalledinMATLAB,theprogramfirst looksinthecurrentfoldertoseeifthefunctionisdefinedIfitcan’tfindthefunctionlistedthere,itstartsdowna predefinedsearchpath,lookingforafilewiththe functionnameToviewthepaththeprogramtakesasitlooksforfiles, select File>SetPathfromthemenubarortype pathtoolContinued….Asmoreandmorefunctionsarecreatedtousein programming,itmaybeneededtomodifythepathtolook inadirectorywherepersonaltoolshavebeenstored.Forexample:supposeyouhavestoredthedegreesto radiansandradianstodegreesfunctionscreatedina directorycalledMy_functions.Youcanaddthisdirectory tothepathbyselectingAddFolderfromthelistofoption buttonsintheSetPathdialogwindow.You’llbe promptedtoeithersupplythefolderlocationorbrowseto findit(showninnextslide)Continued….MATLAB nowfirst looksinto thecurrent folderfor function definitions andthen works downthe modified searchpathContinued….Onceafolderisaddedtothepath,thechangeappliesonly tothecurrentMATLABsession,unlesschangesaresaved permanentlyClearly,permanentchangesshouldnevermaketoa publiccomputerHowever,ifsomeoneel ...
Nội dung trích xuất từ tài liệu:
Lecture note Data visualization - Chapter 27Lecture27RecapFunctionMfilesSyntaxofFunctionMFilesCommentsMultipleInputandOutputFunctionsFunctionswithNoInputorNoOutputAlthoughmostfunctionsneedatleastoneinputand returnatleastoneoutputvalue,insomesituationsno inputsoroutputsarerequiredForexample:considerthisfunction,whichdrawsastar inpolarcoordinates: function[]=star() theta=pi/2:0.8*pi:4.8*pi; r=ones(1,6); polar(theta,r)ThesquarebracketsonthefirstlineindicatethattheContinued….TherearenumerousbuiltinMATLABfunctionsthatdo notrequireanyinput.Forexample: A=clock returnsthecurrenttime: A= 1.0e+003* Columns1through4 2.0050 0.0030 0.0200 0.0150 Columns5through6DeterminingtheNumberofInputandOutputArgumentsTheremaybetimeswhenyouwanttoknowthenumber ofinputargumentsoroutputvaluesassociatedwitha functionMATLABprovidestwobuiltinfunctionsforthispurposeThenarginfunctiondeterminesthenumberofinput argumentsineitherauserdefinedfunctionorabuiltin functionThenameofthefunctionmustbespecifiedasastring,as, forexample:in nargin(sin)Continued….Whennarginisusedinsideauserdefinedfunction,it determineshowmanyinputargumentswereactually enteredThisallowsafunctiontohaveavariablenumberofinputsRecallgraphingfunctionssuchassurfWhensurfhasasinglematrixinput,agraphiscreated, usingthematrixindexnumbersasthex–andy coordinates.Whentherearethreeinputs,x,y,andz, thegraphisbasedonthespecifiedxandy–valuesThenarginfunctionallowstheprogrammertodetermineContinued….Thesurffunctionisanexampleofafunctionwitha variablenumberofinputsIfweusenarginfromthecommandwindowtodetermine thenumberofdeclaredinputs,thereisn’tonecorrect answerThenarginfunctionreturnsanegativenumbertoletus knowthatavariablenumberofinputsarepossible: nargin(surf) ans=1Thenargoutfunctionissimilartonargin,butit determinesthenumberofoutputsfromafunction:Continued….Anexampleofafunctionwithmultipleoutputsismax: nargout(max) ans=2Whenusedinsideauserdefinedfunction,nargout determineshowmanyoutputshavebeenrequestedbythe userConsiderthisexample,inwhichwehaverewrittenthe functiontocreateastar: functionA=star1() theta=pi/2:0.8*pi:4.8*pi; r=ones(1,6);LocalVariablesThevariablesusedinfunctionMfilesareknownaslocal variablesTheonlywayafunctioncancommunicatewiththe workspaceisthroughinputargumentsandtheoutputit returnsAnyvariablesdefinedwithinthefunctionexistonlyfor thefunctiontouseForexample:considerthegfunctionpreviously described: functionoutput=g(x,y) %ThisfunctionmultipliesxandytogetherContinued….Justascalculationsperformedinthecommandwindowor fromascriptMfilecannotaccessvariablesdefinedin functions,functionscannotaccessthevariablesdefinedin theworkspaceThismeansthatfunctionsmustbecompletelyself contained:Theonlywaytheycangetinformationfrom yourprogramisthroughtheinputarguments,andtheonly waytheycandeliverinformationisthroughthefunction outputConsiderafunctionwrittentofindthedistanceanobject fallsduetogravity: functionresult=distance(t)Continued….ThevalueofgmustbeincludedinsidethefunctionItdoesn’tmatterwhetherghasorhasnotbeenusedinthe mainprogramHowgisdefinedishiddentothedistancefunctionunless gisspecifiedinsidethefunctionOfcourse,youcouldalsopassthevalueofgtothe functionasaninputargument: functionresult=distance(g,t) %Thisfunctioncalculatesthedistanceafallingobject GlobalVariablesUnlikelocalvariables,globalvariablesareavailabletoall partsofacomputerprogramIngeneral,itisabadideatodefineglobalvariablesHowever,MATLABprotectsusersfromunintentionally usingaglobalvariablebyrequiringthatitbeidentified bothinthecommandwindowenvironmentandinthe functionthatwilluseitConsiderthedistancefunctiononceagain: functionresult=distance(t) %ThisfunctioncalculatesthedistanceafallingobjectCreatingToolBoxofFunctionsWhenafunctioniscalledinMATLAB,theprogramfirst looksinthecurrentfoldertoseeifthefunctionisdefinedIfitcan’tfindthefunctionlistedthere,itstartsdowna predefinedsearchpath,lookingforafilewiththe functionnameToviewthepaththeprogramtakesasitlooksforfiles, select File>SetPathfromthemenubarortype pathtoolContinued….Asmoreandmorefunctionsarecreatedtousein programming,itmaybeneededtomodifythepathtolook inadirectorywherepersonaltoolshavebeenstored.Forexample:supposeyouhavestoredthedegreesto radiansandradianstodegreesfunctionscreatedina directorycalledMy_functions.Youcanaddthisdirectory tothepathbyselectingAddFolderfromthelistofoption buttonsintheSetPathdialogwindow.You’llbe promptedtoeithersupplythefolderlocationorbrowseto findit(showninnextslide)Continued….MATLAB nowfirst looksinto thecurrent folderfor function definitions andthen works downthe modified searchpathContinued….Onceafolderisaddedtothepath,thechangeappliesonly tothecurrentMATLABsession,unlesschangesaresaved permanentlyClearly,permanentchangesshouldnevermaketoa publiccomputerHowever,ifsomeoneel ...
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 displayTài liệu liên quan:
-
Trực quan hóa dữ liệu: Vai trò & thử thách
10 trang 37 0 0 -
Ebook Eloquent JavaScript - A modern introduction to programming: Part 1
199 trang 33 0 0 -
Ebook Management support systems: Part 2 - Dr. Kamlesh Lakhwani
136 trang 31 0 0 -
Lecture Introduction to computing systems (2/e): Chapter 19 - Yale N. Patt, Sanjay J. Patel
28 trang 30 0 0 -
Ebook Introduction to algorithms (3rd edition)
1313 trang 28 0 0 -
Lecture Data Structures: Lesson 38
71 trang 27 0 0 -
Lecture Data structures and algorithms: Chapter 1 - Introduction
41 trang 26 0 0 -
Lecture note Data visualization - Chapter 22
21 trang 24 0 0 -
169 trang 24 0 0
-
Lecture Data Structures: Lesson 41
18 trang 23 0 0