
9 Managing Application-Defined Data
9-12
2 Set the edit text value from the slider Callback callback. Add this statement
to the slider
Callback.
set(handles.edit1,'String',...
num2str(get(handles.slider1,'Value')));
3 Set the slider value from the edit text Callback callback. To do this, add the
following code to the edit text
Callback.
To update the number or errors, the code must first retrieve the value of the
edit text
UserData property, then increment the count. It then saves the
updated error count in the
UserData property and displays the new count.
val = str2double(get(hObject,'String'));
% 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 the error count.
number_errors = get(hObject,'UserData');
number_errors = number_errors+1;
% Save the changes.
set(hObject,'UserData',slider_data);
% Display new total.
set(hObject,'String',...
['You have entered an invalid entry ',...
num2str(number_errors),' times.']);
end
Kommentare zu diesen Handbüchern