Effacer les filtres
Effacer les filtres

Make GUI Slider behave like iOS frame scroller

2 vues (au cours des 30 derniers jours)
John
John le 7 Sep 2014
Modifié(e) : giacomo le 16 Nov 2017
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?

Réponse acceptée

Geoff Hayes
Geoff Hayes le 7 Sep 2014
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!
  7 commentaires
Geoff Hayes
Geoff Hayes le 15 Nov 2017
giacomo - you would need to show your code so that we can get an idea of how it works and why you might bee seeing this behaviour.
giacomo
giacomo le 16 Nov 2017
Modifié(e) : giacomo le 16 Nov 2017
ok sure.
EDIT: I attached the whole code so it's easier for you to check it. The four variables seem to be loaded fine, then when I change their values with the slider the program gives me errors, saying that all the variables aren't defined (?). In the last function (done_Callback) I tried to use getappdata to store the final edited v1 v2 v3 v4 values back into the workspace. I think the sintax is correct but I can't know if that's the case since I get the undefined variables error before. Thanks.
EDIT2: I also tried to use UIGETVARIABLES (https://es.mathworks.com/matlabcentral/fileexchange/37679-uigetvariables--dialog-to-pass-variables-from-workspace-into-gui) to avoid using evalin, but calling this in the GUI pushbutton9_Callback function:
tvar = uigetvariables({'Pick a scalar:','Pick a scalar:','Pick a
scalar:','Pick a scalar:'}, ...
'InputDimensions',[0 0 0 0]);
v1 = set(handles.value1,'String',num2str(cell2mat(tvar(1))));
%and same for the other 3 variables
prints the variables in the edittext but then when I use the sliders it gives me error: undefined variable v1 etc

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by