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

 Risposta accettata

Voss
Voss il 10 Mag 2024
Modificato: Voss il 10 Mag 2024
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 Commenti

Thank you very much, this is the first time I use this function, I was completely lost.
You're welcome!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulink in Centro assistenza e File Exchange

Prodotti

Release

R2023b

Tag

Richiesto:

il 10 Mag 2024

Commentato:

il 13 Mag 2024

Community Treasure Hunt

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

Start Hunting!

Translated by