User`s guide
Share Data Among a GUI’s Callbacks
'Callback',@slider_callback);
eth = uicontrol(fh,'Style','edi t',...
'String',num2str(get(sh,'Value')),...
'Position',[30 175 240 20],...
'Callback',@edittext_callback);
sth = uicontrol(fh,'Style','tex t','String',...
'Enter a value or click the slider.',...
'Position',[30 215 240 20]);
number_errors = 0;
previous_val = 0;
val = 0;
% ------------F irst Nested Function---------------
% Set the v alue of the edit text component S tring property
% to the va lue of the slider.
function slider _cal lback(hObject,eventdata )
previous_val = val;
val = get(hObject,'Value');
set(eth,'String',num2str(val));
sprintf('You changed the slider value by %6.2f percent.',...
abs(val - previous_val))
end
% ------------- --Se cond Nested Functio n--- -------------
% Set the s lide r value to the number the user types in
% the edit text or display an error message.
function editt ext_ callback(hObject,eventd ata)
previous_val = val;
val = str2double(get(hObject,'St ring'));
% Determine whether val is a number between the
% slider's Min and Max. If it is, set the slider Value.
if isnumeric( val ) && length(val) == 1 && ...
val >= get(sh,'Min') && ...
val <= get(sh,'Max')
set(sh,'Value',val);
sprintf('You changed the slider value by %6.2f percent.',...
abs(val - 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 ',...
13-13