How to set slider's minimum value other than zero in GUI?
7 views (last 30 days)
Show older comments
Hello there, I am trying to change my slider's minimum and maximum values, but I can't do it. I have tried both manually and by programming but the problem is same. The problem is that if I set the minimum value of slider other than zero then after running my gui the slider doesnot appear and the following warning is displayed in command window
Warning: 'slider' control cannot have a 'Value' outside of 'Min'-'Max' range
Control will not be rendered until all of its parameter values are valid
I am using this code in my gui opening function
set(handles.slider1,'Min',3)
set(handles.slider1,'Max',25)
I am using MATLAB R2017a
0 Comments
Answers (2)
Stephen23
on 24 Feb 2019
Edited: Stephen23
on 24 Feb 2019
Read the error message:
Warning: 'slider' control cannot have a 'Value' outside of 'Min'-'Max' range
So you just need to also change the value to suit those new limits, e.g.:
set(handles.slider1, 'Max',25, 'Value',3, 'Min',3)
Here is a complete working example:
>> uih = uicontrol('Style','slider');
>> set(uih,'Max',23, 'Value',3, 'Min',3) % no error!
If you really want separate set calls:
set(handles.slider1, 'Max',25)
set(handles.slider1, 'Value',3)
set(handles.slider1, 'Min',3)
2 Comments
Stephen23
on 25 Feb 2019
Edited: Stephen23
on 25 Feb 2019
"Why is this so that when I change these limits through property editor in gui then there is a warning and if I change these limits of slider in m-file then it works fine?"
Because of the order in which you change them. You are in control of three numbers, and you have to ensure that one of them (Value) must always be in between the other two (Min and Max), otherwise you will get that warning. You are changing them in an order which causes Value to be outside of the Min-Max range. It is that simple.
Assuming that the slider is constucted with the default values (min=0, max=1, value=0), then in your original question this was your very first step:
set(handles.slider1,'Min',3) % -> WARNING as Value is less than Min!
Similarly, these would also show that warning (assuming each as a first step):
set(handles.slider1,'Value',25) % -> WARNING as Value is greater than Max!
set(handles.slider1,'Value',-9) % -> WARNING as Value is less than Min!
If you want to increase the Min limit without getting that warning, you will need to increase the Value beforehand (to a number greater that the new Min, which might also require setting Max first), exactly as I showed in my answer. Then you will not get that warning.
Would you expect to be able to set Value to 99 with limits of [0,1] ? Or if Max is less than Min? What would be displayed in the GUI? In exactly the same way, you cannot expect to set Min to 3 if the Value is still 0.
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!