《科学计算科学计算 (49).pdf》由会员分享,可在线阅读,更多相关《科学计算科学计算 (49).pdf(20页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、8.5 App Development Using App Designer8.5 App Development Using App DesignerApp is the short for application program.Here App means MATLABprograms with a graphical user interface(GUI).App DesignerApp ComponentsApp1 1App DesignerApp DesignerApp Designer is a rich development environment for building
2、apps.In addition to standard components,App Designer offers gauges,lamps,knobs,and switches for inclusion in your app.App Designer generates code that is structured to facilitate app development and data sharing across the app.(1)Open App DesignerAt the MATLAB command prompt,type appdesigner.On the
3、MATLAB Home tab,select New App App Designer.(2)App Designer QuickAccess Toolbar(QAT)RibbonDesign Area1 1App DesignerApp Designer(3)CanvasDesign View:to edit the user interfaceCode View:for editing,debugging,and analyzing code1 1App DesignerApp Designer(3)CanvasDesign view Component Library Component
4、 BrowserInspector tab is used to view or set properties that control the appearanceof the component.1 1App DesignerApp Designer(3)CanvasCode View Code Browser APP Layout Component Browser Inspector tab is used to view or set properties that control the behavior of the component.1 1App DesignerApp De
5、signerCommon ComponentsContainersInstrumentation Components2 2Components in App Components in App DesignerDesignerSaveAppFile:AppDemo.mlappAdd ComponentsKnobDiscre KnobButtonButtonGroup and Radio ButtonUIAxesExample 1:Create an App user interface,.The interface includes 1 axes,2 knobs,2 buttons and
6、1 button group.(1)Start App Designer.(2)Set properties of componentSet Knob propertiesValue,Maximum,MinimumTicks IntervalLabel under the KnobLabel text under the DiscreteKnobSet ButtonGroup propertiesTitle of ButtonGroupText of RadioButtonsLabel of Buttons2 2Components in App Components in App Desig
7、nerDesigner2 2Components in App Components in App DesignerDesigner(2)Set properties of component2 2Components in App Components in App DesignerDesigner(2)Set properties of componentTurn to Code View.In the Component Browser,Select the DiscreteKnob.Then in the Property Inspector,set Value,Maximum,Min
8、imum of the DiscreteKnob.(3)Write CallbacksIn code Code View,in the Editor tab,click Callbacks.Or in the Code Browser on theCallbacks tab,click the button.Right-click a component in the canvas,Component Browser,or App Layout pane,andselect Callbacks Add(callback property)callback.2 2Components in Ap
9、p Components in App DesignerDesignerApp Designer uses object-oriented programming to create an app.Objects declaration,functions,properties and shared data are all packaged in a class.An MLApp file is defined as a class.(1)Basic framework of MATLAB classProperties block is the properties definition,
10、mainly including properties declaration.Methods block is the methods definition,including several functions.The callback functionhas only one argument,App,which is the UI handle.It stores data of each member in theinterface.3 3Programming in Programming in App DesignerApp Designer(1)Basic framework
11、of MATLAB classclassdef ClassName matlab.apps.AppBaseproperties(Access=public)endmethods(Access=private)function Function1(app)endfunction Function2(app)endendend3 3Programming in Programming in App DesignerApp DesignerAccessing data and calling functions are called access object members.(2)Permissi
12、ons for accessThe public members can be used to share data with other classes of the app.The private members can be accessed in the class only,including:Property declaration The startupFcn function The createComponents function Other callback function3 3Programming in Programming in App DesignerApp
13、DesignerExample 2:Perform the drawing function in Example 1.Click the Draw button,to plot the sine curve with the Value of the Frequency Multiplier Knob and the Value of the Phase Angle Knob.Click the Clear button to clear the graph in the axes.Select Add ButtonPushedFcn callback item from the Draw
14、button right-click context menu.function Draw_Plot(app)f=eval(app.DiscreteKnob.Value);%Get Value of DiscreteKnobtheta=app.Knob.Value/180*pi;%Get Value of Knobx=linspace(0,2*pi,60);if app.RadioButton.Value=1 y=sin(f*x+theta);elsey=cos(f*x+theta);End%The first argument of th plot function must be a UI
15、Axes%LineWidth of Lines in App must 0.4plot(app.UIAxes,x,y,LineWidth,0.2);endCode behavior of the app in the methods blockCallback function of Draw buttonfunction Clear_Axes(app)cla(app.UIAxes)endCode behavior of the app in the methods blockCallback function of Clear button(3)Run the appOn the file
16、in App Designer,click Run on the toolstrip,or press F5 key.Double-Click the MLApp file in Current Folder.Type the MLApp file name at the MATLAB command prompt.3 3Programming in Programming in App DesignerApp Designer(4)Package the appClick the Package App button in the toolbar on the Designer tab of App Designer.It will open the Package App dialog box.3 3Programming in Programming in App DesignerApp Designer