banner



Create Callback For Tab Selection App Designer Matlab

Startup Tasks and Input Arguments in App Designer

App Designer allows you to create a special function that executes when the app starts up, but before the user interacts with the UI. This function is called the startupFcn callback, and it is useful for setting default values, initializing variables, or executing commands that affect initial state of the app. For example, you might use the startupFcn callback to display a default plot or a show a list of default values in a table.

Create a startupFcn Callback

To create a startupFcn callback, right-click the app node from the top of the Component Browser hierarchy, and select > . The app node has the same name as your MLAPP file.

Content menu for the app node in the Component browser.

App designer creates the function and places the cursor in the body of the function. Add commands to this function as you would do for any callback function. Then save and run your app.

Function definition for the startupFcn. The function is in a private methods block, and has one input argument, named app.

See App with Auto-Reflow That Updates Plot Based on User Selections for an example of an app that has a startupFcn callback.

Define Input App Arguments

The startupFcn callback is also the function where you can define input arguments for your app. Input arguments are useful for letting the user (or another app) specify initial values when the app starts up.

To add input arguments to an app, open the app in App Designer and click Code View. Then click App Input Arguments in the Editor tab.

App Input Arguments dialog. The dialog contains an edit field for entering arguments for the startupFcn callback.

The App Input Arguments dialog box allows you to add or remove input arguments in the function signature of the startupFcn callback. The app argument is always first, so you cannot change that part of the signature. Enter a comma-separated list of variable names for your input arguments. You can also enter varargin to make any of the arguments optional. Then click OK.

After you click OK, App Designer creates a startupFcn callback that has the function signature you defined in the dialog box. If your app already has a startupFcn callback, then the function signature is updated to include the new input arguments.

After you have created the input arguments and coded the startupFcn, you can test the app. Expand the drop-down list from the Run button in the toolstrip. In the second menu item, specify comma-separated values for each input argument. The app runs after you enter the values and press Enter.

Run button menu options. The options are to run the app with no arguments, to run the app by specifying input arguments, and to edit app input arguments.

Note

MATLAB® might return an error if you click the Run button without entering input arguments in the drop-down list. The error occurs because the app has required input arguments that you did not specify.

After successfully running the app with a set of input arguments, the Run button icon contains a blue circle.

Run button with a blue circle.

The blue circle indicates that your last set of input values are available for re-running your app without having to type them again. Up to seven sets of input values are available to choose from. Click the top half of the Run button to re-run the app with the last set of values. Or, click the bottom half of the Run button and select one of the previous sets of values.

The Run button also allows you to change the list of arguments in the function signature. Select from the drop-down list in the bottom half of the Run button.

Run button menu options.

Alternatively, you can open the same App Input Arguments dialog box by clicking App Input Arguments in the toolstrip, or by right-clicking the startupFcn callback in the Code Browser.

See Create Multiwindow Apps in App Designer for an example of an app that uses input arguments.

Related Topics

  • Write Callbacks in App Designer
  • Create Multiwindow Apps in App Designer

Create Callback For Tab Selection App Designer Matlab

Source: https://ww2.mathworks.cn/help/matlab/creating_guis/app-designer-startup-function.html?lang=en

Posted by: joneslieve1996.blogspot.com

0 Response to "Create Callback For Tab Selection App Designer Matlab"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel