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

 Respuesta aceptada

Voss
Voss el 10 de Mayo de 2024
Editada: Voss el 10 de Mayo de 2024

0 votos

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 comentarios

Thierry Gouzenne
Thierry Gouzenne el 13 de Mayo de 2024
Thank you very much, this is the first time I use this function, I was completely lost.
Voss
Voss el 13 de Mayo de 2024
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink en Centro de ayuda y File Exchange.

Productos

Versión

R2023b

Etiquetas

Preguntada:

el 10 de Mayo de 2024

Comentada:

el 13 de Mayo de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by