Share function output within callback with another callback in App Designer

7 views (last 30 days)
I am fairly new to App Designer, and am trying to write a function which takes in data from a specified excel file. The excel file name is specified by the user in an "edit text" object. The data is read within a button callback, shown below:
function ReadDataButtonPushed(app, event)
dataname = app.DataFileEditField.Value;
data = readtable(dataname)
app.DataReadLamp.Color = [0,1,0];
[CylPress, IntakePress, headers, Colnum] = EngineDataClean(data);
end
However, I need the outputs of the EngineDataClean function to be available to other callbacks. Due to the size of the excel files being read, its not feasible to read the data for each subsequent callback. Is there a way to make these function outputs global?

Accepted Answer

Ameer Hamza
Ameer Hamza on 2 Jun 2020
You can do so using properties. Switch to code view, and on the toolbar, click the "Property" button to add a new property to your app. You need to add four properties and give them names CylPress, IntakePress, headers, and Colnum. Then change the line in your function like this
[app.CylPress, app.IntakePress, app.headers, app.Colnum] = EngineDataClean(data);
you can access variables in other callbacks or functions inside your app using 'app' object
app.CylPress % will return value of CylPress, similar for other variables

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!