Reputation: 57
checkbox1's callback for date and time:
m=1;
while m==1
m=get(hObject,'value');
txt=datestr(now);
set(handles.datetime,'string',txt);
pause(1);
end
can you please help me to remove the checkbox that if I will push the RUN button the datetime static text will automatically call the date and time.
EDIT REPLY:
I used your code and this is how it looks like.
Upvotes: 0
Views: 680
Reputation: 2359
Have a look to this post.
Do a toogle button that have 2 status : Run/Stop. So you will push your button and do
if (get(hObject,'value'))
set(handles.toogleRun,'string','stop');
else
set(handles.toogleRun,'string','Run');
end
while (get(hObject,'value'))
txt=datestr(now);
set(handles.datetime,'string',txt);
drawnow;
end
This is the callback for the toogleRun button.
EDIT : So for using the timer instead use that code :
function my_callback_fcn(obj, event)
txt = datestr(now)
set(handles.datetime,'string',txt);
And into your Opening GUI function create a timer and set is callback function to the function you already create.
t = timer('StartDelay', 1, 'Period', 0.1);
t.TimerFcn = {@my_callback_fcn};
So just add start(t)
on a button or whatever
Upvotes: 0