Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Matlab GUI with timer in the background
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Nima Nikvand

Posts: 11
Registered: 12/30/12
Matlab GUI with timer in the background
Posted: Jan 6, 2013 12:17 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hello everyone,

I have a GUI (developed using guide) and I need to show the current time and date in one of its corners, I have written a simple code which works alright, however I am not sure where in the GUI code to use it. When I use the code in GUI_OpeningFcn, which executes just before gui is made visible, it shows the time but MATLAB remains busy and I won't be able to run anything else from the command window, furthermore, I am not sure how to stop the timer and delete the timer when the GUI is closed. When I use handles to save timer created in OpeningFcn and later delete the timer in OutputFcn, I get an error saying my handle is invalid! The code is posted below and I appreciate any help with this.

timex=timer;

set(timex,'executionMode','fixedRate');
set(timex,'timerFcn',{@timexup,handles});
set(timex,'period',1);
start(timex);
%handles.output=0;
if(~ishandle(handles))
stop(timex);
delete(timex);
end

function timexup(obj,event,handles)
set(handles.text6,'string','');
pause(0.5);
set(handles.text6,'string',num2str(datestr(now)));
set(handles.text6,'Fontsize', 10, 'FontWeight', 'bold');
pause(0.5);



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.