MATLAB: How to vary the value of a edit text in matlab gui

timer

I am writing a code which refreshes the value of a text box in gui periodically .But each time my code gives me error "Error while evaluating TimerFcn for timer 'timer-19' H must be the handle to a figure or figure descendent. I have put the timer in the push button callback function so that the timer starts executing once the push button is pressed.
function s_Callback(hObject, eventdata, handles)
handles.t= timer('Execution','fixedRate','Period',4.0);
set(handles.t,'TimerFcn',{@u,hObject});
start(handles.t);
The function to be executed is
function u(hObject, eventdata, handles)
handles=guidata(hObject);
a=1;
set(handles.u,'String',a);
Any help would be appreciated .

Best Answer

The first argument passed to a timer's TimerFcn, which you have called hObject in your u function, is the timer object. The argument passed into guidata must be a graphics object, so you cannot call guidata(hObject) within u. I would guess this is causing the error. Instead, call guidata on the handles variable which you pass into u:
function u(hObject, eventdata, handles)
handles=guidata(handles);
a=1;
set(handles.u,'String',a);
Related Question