How to set slider's minimum value other than zero in GUI?

조회 수: 16 (최근 30일)
GMD Baloch
GMD Baloch 2019년 2월 24일
편집: John Doe 2020년 5월 17일
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

답변 (2개)

Stephen23
Stephen23 2019년 2월 24일
편집: Stephen23 2019년 2월 24일
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
GMD Baloch
GMD Baloch 2019년 2월 25일
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?
Stephen23
Stephen23 2019년 2월 25일
편집: Stephen23 2019년 2월 25일
"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.

댓글을 달려면 로그인하십시오.


John Doe
John Doe 2020년 5월 17일
편집: John Doe 2020년 5월 17일
You can double click on the slider, and set the property of 'Value' in between Min-Max range to get rid of the warning.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by