MATLAB Creating Graphical User Interfaces

(ff) #1

Share Data Within App Designer Apps


NoteFor information on sharing data in apps you create using GUIDE, see “Share Data
Among Callbacks” on page 11-2.

Using properties is the best way to share data within an app because properties are
accessible to all functions and callbacks in an app. All UI components are properties, so
you can use this syntax to access and update UI components within your callbacks:

app.Component.Property

For example, these commands get and set the Value property of a gauge. In this case,
the name of the gauge is PressureGauge.

x = app.PressureGauge.Value; % Get the gauge value
app.PressureGauge.Value = 50; % Set the gauge value to 50

However, if you want to share an intermediate result, or data that multiple callbacks need
to access, then define a public or private property to store your data. Public properties
are accessible both inside and outside of the app, whereas private properties are only
accessible inside of the app. Code View provides a few different ways to create a
property:


  • Expand the drop-down menu from the bottom half of the Properties button in the
    Editor tab. Select Private Property or Public Property.


Share Data Within App Designer Apps
Free download pdf