Saving data in a GUI callback function

6 ビュー (過去 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 Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by