Execute command if timer runs out

1 回表示 (過去 30 日間)
Taylor Hearn
Taylor Hearn 2019 年 5 月 10 日
コメント済み: Taylor Hearn 2019 年 5 月 14 日
I am developing an App in the App Designer, and I would like to have a block of code run if a timer expires. So basically, if a button is pressed within a certain time window, code A runs, but if no button is pressed within that time window, code B runs. Any suggestions? Thanks in advance!

採用された回答

Josh
Josh 2019 年 5 月 11 日
A timer object might work:
% Define callback
callback = @(x,y)disp('hello world');
% Create timer; this will execute TimerFcn after the 10s StartDelay has elapsed
t = timer( ...
'ExecutionMode', 'singleShot', ...
'StartDelay', 10, ...
'TimerFcn', callback);
% Start timer
start(t);
  1 件のコメント
Taylor Hearn
Taylor Hearn 2019 年 5 月 14 日
This is perfect! Combined with an if statement in the callback function this should do exactly what I'm aiming for. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by