Make GUI Slider behave like iOS frame scroller
4 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Geoff Hayes
2014-9-7
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 个评论
Geoff Hayes
2017-11-15
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
2017-11-16
编辑:giacomo
2017-11-16
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!