
Undocumented Secrets of MATLAB
®
-Java Programming198
Now, attach undo/redo actions to the slider’s callback:
set(hSlider,'Callback',@test_uiundo);
% Main callback function for slider updates
function test_uiundo(varargin)
% Update the edit box with the new value
hEditbox = get(gcbo,'userdata');
newValue = get(gcbo,'value');
set(hEditbox,'string',num2str(newValue));
% Retrieve and update the stored previous value
oldValue = getappdata(gcbo,'oldValue');
if isempty(oldValue), oldValue=0; end
setappdata(gcbo,'oldValue',newValue);
% Prepare an undo/redo action
cmd.Name = sprintf('slider update (%g to %g)',oldValue,newValue);
% Note: the following is not ...