%*********************************************************************%
% Name of the GUI is 'dummy' %
%*********************************************************************%
%*********************************************************************%
% Initialize count to zero in the GUI opening function %
%*********************************************************************%
function dummy_OpeningFcn(hObject, eventdata, handles, varargin)
handles.count=0;
set(handles.text1,'String',num2str(handles.count));
handles.output = hObject;
guidata(hObject, handles);
%*******************************************************************************
% increase the count and update the static text box using pushbutton callback %
%******************************************************************************%
function pushbutton1_Callback(hObject, eventdata, handles)
handles.count=handles.count+1;
set(handles.text1,'String',num2str(handles.count));
In the above code the variable handles.count is initialized as '0' in the opening function of the GUI and the pushbutton callback is supposed increase the count on each click and update the contents of a static textbox. But surprisingly the variable handles.count becomes '0' each time I access it in the button's callback function and as a result the content of static textbox is always '1'.