Execute command if timer runs out

1 Ansicht (letzte 30 Tage)
Taylor Hearn
Taylor Hearn am 10 Mai 2019
Kommentiert: Taylor Hearn am 14 Mai 2019
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!

Akzeptierte Antwort

Josh
Josh am 11 Mai 2019
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 Kommentar
Taylor Hearn
Taylor Hearn am 14 Mai 2019
This is perfect! Combined with an if statement in the callback function this should do exactly what I'm aiming for. Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by