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 ExchangeSimulink についてさらに検索

製品

リリース

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