MATLAB Creating Graphical User Interfaces

(ff) #1
Sharing Data Within Your App

To store data, and share it among different callbacks, create a custom property. For
example, you might want your app to read a data file and allow different callbacks in your
app to access that data.

To create a property, expand the Property drop-down in the Editor tab, and select
Private Property or Public Property. App Designer creates a template property
definition and places your cursor next to that definition. Change the name of the property
as desired.

properties (Access = public)
X % Average cost
end

To reference the property in your code, use dot notation of the form app.Propertyname.
For example, app.X references the property named X.

For more information about creating and using custom properties, see “Share Data Within
App Designer Apps” on page 17-29.

Single-Sourcing Code that Runs in Multiple Places

If you want to execute a block of code in multiple parts of your app, create a helper
function. For example, you might want to update a plot after the user changes a number
in an edit field or selects an item in a drop-down list. Creating a helper function allows
you to single-source the common commands and avoid having to maintain redundant sets
of code.

To add a helper function, expand the Function drop-down in the Editor tab, and
select Private Function or Public Function. App Designer creates a template function
and places your cursor in the body of that function.

To delete a helper function, select the function name in the Functions tab of the Code
Browser and press the Delete key.

For more information about writing helper functions, see “Create Helper Functions in App
Designer” on page 17-25.

Creating Input Arguments

To add input arguments to your app, click App Input Arguments in the Editor tab.
Input arguments are commonly used for creating apps that have multiple windows. For

17 App Programming

Free download pdf