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일

0 개 추천

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

Thierry Gouzenne
Thierry Gouzenne 2024년 5월 13일
Thank you very much, this is the first time I use this function, I was completely lost.
Voss
Voss 2024년 5월 13일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

제품

릴리스

R2023b

태그

질문:

2024년 5월 10일

댓글:

2024년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by