User`s guide
Ways to Manage Data in a GUIDE GUI
• When a user types a value into the edit text component, the slider updates
to this value.
• If a user enters a value in the edit text that is out of range for the slider
(a value that is not between 0 and 1), the application returns a message
in the edit text component that indicates the number of times the user
entered an incorrect value.
The commands in the following steps initialize the error counter an d
implement the interchange between the slider and the edit text component:
1 Define the error counter in the opening function. The GUI records the
number of times a user enters an incorrect value in the edit text component
andstoresthisnumberinafieldofthe
handles structure.
Define the
number_errors field in the opening function as follows:
% INITIALIZE ERROR COUNT AND USE GUIDATA TO UPDATE THE HAND LES STRUCTURE.
handles.number_errors = 0;
Place it above the following line, which GUIDE automatically inserts into
the opening function:
guidata(hObject,handles);
The guidata command saves the modified handles structure so that it can
be retrieved in the GUI’s callbacks.
2 Set the value of the edit text component Stri ng property from the slider
callback. The following command in the slider callback updates the value
displayed in the edit text component when a user moves the slider and
releases the mouse button:
set(handles.edittext1,'String',...
num2str(get(handles.slider1,'Value') ));
This code combines three commands:
• The
get command obtains the current value of the slider.
• The
num2str command converts the value to a string.
9-19