How to enable a button after x seconds in MATLAB GUI?
    9 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Hi,
I am recording an audio. I have a start button and a stop button in GUI. When someone clicks start, the audio starts getting recorded.
Now, I want to enable the stop button only after x seconds. Where x could be 0.5 seconds, 1 seconds or whatever. How could I know that x seconds have passed and now its time to turn on the stop button.
Basically, I don't know how to start a clock and obtain its value. Can someone please help me with it?
Thank you.
0 commentaires
Réponse acceptée
  Paulo Silva
      
 le 25 Juin 2011
        function testtimebutton
figure
t = timer('TimerFcn','nan;','StopFcn',@endtimer, 'startdelay',... 2,'ExecutionMode','singleshot');
pbh1 = uicontrol(gcf,'Style','pushbutton','String','Start timer',...
    'Position',[10 90 60 40],...
    'callback',@stimer);
pbh2 = uicontrol(gcf,'Style','pushbutton','String','Button',...
    'Position',[10 30 60 40],...
    'enable','off','callback','disp(''You pressed the Button'')');
      function endtimer(obj,event)
          set(pbh2,'enable','on')
          disp('timer stopped, Button enabled')
      end
      function stimer(obj,event)
          start(t)
          disp('timer started')
          set(pbh2,'enable','off')
      end
end
2 commentaires
  Paulo Silva
      
 le 25 Juin 2011
				 %code to start recording and start record
 set(hObject,'enable','off')
 pause(2)
 set(hObject,'enable','on')
 %now the user can click again on the button
Plus de réponses (1)
Voir également
Catégories
				En savoir plus sur Clocks and Timers dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


