function untitled2()

global im;

% an image
im = rand(100);

% slider for window/level
h = uicontrol('style','slider','units','normalized','position',[0.91 0.86 0.08 0.04]);

set(h,'Value', 1);
set(h,'Min', eps);
set(h,'Max', 2);
set(h,'Tag', 'mySlider');
set(h,'Callback', @callback);

% respond to slider in real time
addlistener(h,'Value','PostSet',@callback);

% initialize
callback([],[]);

end


% event listener for slider
function callback(src,event)

global im;

    % get the slider value
    obj = get(gcf,'Children');

    for k = 1:numel(obj)
        if isequal(get(obj(k),'Tag'),'mySlider')
            value = get(obj(k),'Value');
        end
    end

    % image to display
    imagesc(im,[0 value]); title(value);

end
