Auto save file in running GUI

2 ビュー (過去 30 日間)
Cristian Martin
Cristian Martin 2022 年 5 月 26 日
コメント済み: Voss 2022 年 5 月 28 日
Hi,
I have a GUI that runs more then 5-6 hours
There's a command for this script to be executed every 'x' minutes ? I want to save file every 30 min for example. Actually that script is from a push button
tableData = get(handles.uitable1, 'data');
tableData = cell2table(tableData);
filename = sprintf('%s.csv', datestr(now, 'dd.mm.yyyy.HHMM'));
writetable(tableData,filename);

採用された回答

Voss
Voss 2022 年 5 月 28 日
Maybe you can use a timer for this. (https://www.mathworks.com/help/matlab/ref/timer.html)
You could create the timer in the OpeningFcn:
handles.save_timer = timer( ...
'ExecutionMode','fixedRate', ...
'Period',1800, ... % 30 min = 1800 s
'TimerFcn',{@cb_save_table,handles.figure1}); % <- pass the figure to the TimerFcn
Start the timer when the process that takes > 5-6 hours starts (that might be when the GUI starts (OpeningFcn) or it might be in a Callback in the GUI):
start(handles.save_timer);
And define the TimerFcn of the timer to be the callback you posted, which saves the table data to file:
function cb_save_table(src,evt,fig)
handles = guidata(fig);
writetable( ...
cell2table(get(handles.uitable1, 'data')), ...
sprintf('%s.csv', datestr(now, 'dd.mm.yyyy.HHMM')));
end
  2 件のコメント
Cristian Martin
Cristian Martin 2022 年 5 月 28 日
Thank you for the answer!
Voss
Voss 2022 年 5 月 28 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by