User`s guide

13 Manage Application-Defined Data
slider_data.previous_val = slide r_data.val;
slider_data.val = str2double(get(hObject,'String'));
% Determine whether val is a number between the
% slider's Min and Max. If it is, set the slider Value.
if isnumeric( sli der_data.val) && .. .
length(slider_data.val) == 1 && ...
slider_data.val >= get(sh,'Min') && ...
slider_data.val <= get(sh,'Max')
set(sh,'Value',slider_data.val);
sprintf('You changed the slider value by %6.2f percent.',...
abs(slider_data.val - slider_da ta.previous_val))
else
% Increment the error count, and display it.
number_errors = number_errors+1;
set(hObject,'String',...
['You have entered an inval id entry ',...
num2str(number_errors),' times.']);
slider_data.val = slider_data.previous_val;
end
% Save appdata before return ing.
setappdata(fh,'slider',slider_data);
end
end
Slider Values. In this example, both the slider callback, slide r_c allback,
and the edit text callback,
edittext_callback, retrieve the slider_data
application data structure, which holds previous and current values
of the slider. They then save the value,
slider_data.val to
slider_data.previous_val before retrieving the new value and assigning it
to
slider_data.val. Before returning, each callback saves the slider_data
structure in the sl ider application data.
% Get 'slider' appdata.
slider_data = getappdata(fh,'slider');
slider_data.previous_val = slid er_data.val;
slider_data.val = str2double(get(hObject,'String'));
...
% Save 'slider' appdata bef ore returning.
setappdata(fh,'slider',slider_data)
13-20