Saving data in a GUI callback function

조회 수: 14 (최근 30일)
Giulia Pötgens
Giulia Pötgens 2021년 7월 30일
답변: Mohammad Sami 2021년 8월 2일
I don't fully understand how to save data acquired through a GUI callback function, so I can use in another callback function. I want to save some variables in one function, everytime it is run, and then when another button is pushed all these data are written to an Excel file. I've tried the guidata function, but I don't really understand how to use hObject or handles. I've also found other functions for this, but it's unclear to me how to use them.
function SnapshotButtonPushed(app, event)
ind = app.SamplenumberEditField.Value;
%% Make picture
im = f_camera();
%% Detection
amount = f_detect
%% Save endtime and concentration to excel file
table_amount{ind} = amount;
table_conc{ind} = concentration;
table_endtimes{ind} = datestr(now,'HH:MM:SS');
hObject= %?
guidata(hObject,struct(ind, table_amount, ind, table_conc, ind,table_endtimes)); %Is this correct?
function ButtonPushed2(app, event)
ind = app.SamplenumberEditField.Value;
table_sample{ind} = ind;
table_name{ind} = 'name';
filename = 'Format.xlsx';
xlswrite('Format.xlsx',table_name,'Sheet1','A2')
xlswrite('Format.xlsx',table_sample,'Sheet1','B2')
xlswrite('Format.xlsx',table_endtimes,'Sheet1','G2')
xlswrite('Format.xlsx',table_amount,'Sheet1','H2')
xlswrite('Format',table_conc,'Sheet1','I2')
winopen('Format.xlsx')

채택된 답변

Mohammad Sami
Mohammad Sami 2021년 8월 2일
With app designer you don't need guidata and hobject to store your data.
Create properties in your app and then you can access them from inside any app function using app.propertyname.
For more information read the documentation here
https://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html
For example
function f1(app)
% .... %
app.table_name = some_table
% .... %
end
function f2(app)
% .... %
xlswrite('Format.xlsx',app.table_name,'Sheet1','A2');
% .... %
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by