User`s guide

Ways to Manage Data in a GUIDE GUI
This section shows you h ow to use GUI data to initialize and maintain an
error counter by storing an error count in the edit text component’s
UserData
property.
1 Add the following code to the opening function to initialize the edit
text component’s
UserData property. This code initializes the data in a
structure to allow for other data that could be needed:
% INITIALIZE ERROR COUNT AND USE EDITTEXT1 OBJECT'S USERDATA TO STORE IT.
data.number_errors = 0;
set(handles.edittext1,'UserData',data)
Note Alternatively, you can add a CreateFcn callback for the edit text, and
initialize the error counter there.
2 Add the following s tatement to set the edit text value from the slider
callback:
set(handles.edittext1,'String',...
num2str(get(hObject,'Value')));
where hObject is the handle o f the slider.
3 Add the following lines of code to the edit text callback to set the slider
value from the edit text callback:
val = str2double(get(hObject,'Stri ng'));
% Determine whether val is a number between 0 and 1.
if isnumeric (val ) && length(val)==1 && ...
val >= get(handles.slider1,'Min ') && ...
val <= get(handles.slider1,'Max ')
set(handles.slider1,'Value',val);
else
% Retrieve and increment th e error count.
% Error count is in the edit text UserData ,
% so we already have its handle.
data = get(hObject,'UserData');
data.number_errors = data.numbe r_errors+1;
% Save the changes.
9-13