Share function output within callback with another callback in App Designer

5 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

Ameer Hamza
Ameer Hamza le 2 Juin 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
  2 commentaires
Kevin Johnston
Kevin Johnston le 4 Juin 2020
Exactly what I needed, thank you!
Ameer Hamza
Ameer Hamza le 5 Juin 2020
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by