Share function output within callback with another callback in App Designer

조회 수: 7 (최근 30일)
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?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 6월 2일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by