MATLAB: Make GUI Slider behave like iOS frame scroller

MATLABmatlab slider frame scrubber

It is my understanding that the MATLAB GUI Slider cannot be made to behave like a frame scrubber. Suppose I have a Slider control that is used to control which frame of a video sequence is rendered on an Axes control, and I drag the Slider knob (the thing in the slider bar that moves left and right or up and down), it will not update the Value property (which tells you the current position of the knob in the Slider ) until the left mouse button is released.
Does anyone know if there is a way to make the Slider control in MATLAB's GUI facilities behave like the iOS frame scrubber?

Best Answer

John - you can try implementing a continuous value change listener for your slider. That way, as the slider "button" moves, you can capture each value change. Assuming that you are using GUIDE, in your GUI, do the following: in the yourGuiName_OpeningFcn, create a listener as
function yourGuiName_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for untitled
handles.output = hObject;
% create the listener for the slider
handles.sliderListener = addlistener(handles.slider1,'ContinuousValueChange', ...
@(hFigure,eventdata) slider1ContValCallback(...
hObject,eventdata));
% update handles structure
guidata(hObject, handles);
In the above we create a listener for the slider (named slider1) which will fire the slider1ContValCallback callback on any change to its value. This callback takes two input parameters - the handle to the figure/GUI, hFigure, and the event data, eventdata (which we won't need, but a second input parameter is required).
Now we add the callback slider1ContValCallback as
function slider1ContValCallback(hFigure,eventdata)
% test it out - get the handles object and display the current value
handles = guidata(hFigure);
fprintf('slider value: %f\n',get(handles.slider1,'Value'));
The above callback simply gets the handles data (so all widget handles and user-defined data) from the figure handle using guidata. We then write out the current value of the slider.
Try the above for either moving the slider with the arrow buttons or manually moving the slider button up or down.
NOTE there will probably be a callback defined already for slider1 as slider1_Callback. This should be removed from the m-file and from the slider itself (because you don't need this callback and the continuous value change callback to both fire). In the GUI, again assuming GUIDE is being used, launch the Property Inspector for the slider and clear the text for the Callback property. The text will be something like
@(hObject,eventdata)yourGuiName('slider1_Callback',hObject,eventdata,guidata(hObject))
Close the inspector, and save. Try the above and see what happens!