GUI slider value change when majorstep is changed from default?
显示 更早的评论
Hello,
i experienced a very strange behaviour of GUI (made with GUIDE) sliders, If I change the major step of a vertical slider, e.g. 0.02 and the minor step is 0.01, the value of the slider changes from 0 to 0.08. The inspector in guide shows 0 for the value, but the thumbbar of the slider is not at the bottommost position. If i start the GUI, the thumbbar is still at the same position, and if i check the value of the slider, it is 0.08 instead of 0.
Test it with a blank gui, add a vertical slider:
- max: 1.0
- min: 0.0
- sliderstep: [0.01,0.02]
- x: 0.01
- y: 0.02
- value: 0.0
when you start the gui, the slider is value is not 0.0
6 个评论
Gaszton
2013-1-14
Sean de Wolski
2013-1-14
Works fine for me...
Sean de Wolski
2013-1-14
I opened a new blank GUIDE gui. Added a slider, made the settings you did and ran it with no wierdness.
R2012b, Win7 Sp1 x64...
To be sure, I added disp(get(hObject,'Value')) to the createFcn and callback and saw only expected results
Gaszton
2013-1-15
回答(3 个)
Azzi Abdelmalek
2013-1-14
编辑:Azzi Abdelmalek
2013-1-14
% In your opening function insert
% slider1 is your slider's tag
set(handles.slider1,'value',0,'Min',0,'Max',1,'Sliderstep',[0.01,0.02])
4 个评论
Gaszton
2013-1-14
Azzi Abdelmalek
2013-1-14
Check if you are not running different files, and be sure they are in your working folder.
Azzi Abdelmalek
2013-1-14
You are right, I'am getting the same problem, which I can't explain
Azzi Abdelmalek
2013-1-14
Try this in this order
set(handles.slider1,'Min',0,'Max',1,'Sliderstep',[0.01,0.02])
set(handles.slider1,'value',0)
%or
set(handles.slider1,'Min',0,'Max',1,'Sliderstep',[0.01,0.02],'value',0)
Image Analyst
2013-1-15
编辑:Image Analyst
2013-1-15
I'm not able to reproduce. I displayed the value in the movement callback and it was exactly as expected: 0.01 after the first small click, and incrementing by 0.01 or 0.02 depending on where in the slider you clicked.
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
sliderValue = get(hObject,'Value') % Spit value out to command line.
return;
The thumbbar of the slider also does not move when I change the step values. Since the value is 0 it stays slammed up against one side. I'm running R2012b 64 bit on Windows 7.
9 个评论
Azzi Abdelmalek
2013-1-15
编辑:Azzi Abdelmalek
2013-1-15
I A, How did you set the parameters? when I set the parameter manually, using Inspector Uicontrol, it works fine, It works also when I set
set(handles.slider1,'Min',0,'Max',1,'Sliderstep',[0.01,0.02])
set(handles.slider1,'value',0)
But when I switch the order
set(handles.slider1,'value',0)
set(handles.slider1,'Min',0,'Max',1,'Sliderstep',[0.01,0.02])
The problem occurred (I am using Matlab 2011b on Windows 7)
Image Analyst
2013-1-15
I did it with property inspector in GUIDE. If you do it there, you don't need to also do it in the OpenFcn function, though I don't think it should hurt. If you are doing it somewhere in code, is the slider actually displayed at that point? Or is it still now shown yet and in the process of creating the GUI for initial display? I think I remember in the past where sometimes I couldn't do things if the control wasn't displayed yet.
Azzi Abdelmalek
2013-1-15
I know, I'am just trying to find what is causing the problem. Try
set(handles.slider1,'value',0)
set(handles.slider1,'Min',0,'Max',1,'Sliderstep',[0.01,0.02])
that causes the problem
Azzi Abdelmalek
2013-1-16
编辑:Azzi Abdelmalek
2013-1-16
Have you tried to do it in this order?
set(handles.slider1,'Min',0,'Max',1,'Sliderstep',[0.01,0.02])
set(handles.slider1,'value',0)
Also, if you did it in the inspector, you don't need it to do it in open function.
Jan
2013-1-16
What happens if you set the value to 1 at first?
Gaszton
2013-1-17
Jan
2013-1-18
So would this be a work aorund?
set(handles.slider1, 'value', 1);
drawnow;
set(handles.slider1, 'value', 0);
类别
在 帮助中心 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!