Timer function to refresh the data

Hello,
I want to make an application that allows me to load the file, process the data and display on a graph. I would like to refresh the data every 5 seconds, by restarting the "live" function, but I have trouble understanding the "Timer" function.
Do you have any ideas?Thank you in advance.
function LiveButtonPushed(app, event)
%utilisation de la fonction charger
donnees=charger(app.entrees,app.variables_stockees.conditions_essai.plan);
app.variables_stockees.entrees=app.entrees;
app.variables_stockees.donnees=donnees;
%utilisation de la fonction masquer
masque=masquer(app.variables_stockees);
app.variables_stockees.masque=masque;
%calcul
calcul(app.variables_stockees,app);
timerObj = timer('TimerFcn', @app.LiveButtonPushed, 'Period', 5);
start (timerObj);
end

 采纳的回答

Voss
Voss 2024-5-10
编辑:Voss 2024-5-10
Make timerObj an app property so that the functions within your app can access it.
properties (Access = private)
timerObj
Create the timer somewhere else besides its own TimerFcn, e.g., in the app's StartupFcn:
function startupFcn(app)
app.timerObj = timer('TimerFcn', @(~,~)app.StartButtonPushed, 'Period', 5, 'ExecutionMode', 'fixedRate');
end
The default 'ExecutionMode' is 'singleShot', which causes the TimerFcn to be executed one time. Since you want the TimerFcn to be executed repeatedly every 5 seconds, you should specify another ExecutionMode, e.g., 'fixedRate'.
Start the timer in some function where it makes sense to do so. If you start it in its own TimerFcn, then you should make sure it's not already running when you try to start it:
if ~strcmp(app.timerObj.Running,'on')
start(app.timerObj)
end

2 个评论

Thank you very much, this is the first time I use this function, I was completely lost.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Simulink 的更多信息

产品

版本

R2023b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by