Setting the variable range of Slider in GUI
4 views (last 30 days)
Show older comments
Hello everyone! I'd like to set a variable MIN and MAX of slider in GUI. These values will be entered by user in 'cell_min' and 'cell_max'. The result of position of slider appears in 'cell_output'. I also enclose a adequate part of my code below:
function slider1_Callback(hObject, eventdata, handles)
variableMax=str2num(get(handles.cell_max,'String'));
variableMin=str2num(get(handles.cell_min,'String'));
set(handles.slider1,'MIN',variableMin,'MAX',variableMax);
valor=get(hObject,'value');
set(handles.cell_output,'string', num2str(valor));
guidata(hObject,handles);
For reasons unknown for me, it does not work. The alert which appears:
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
The slider also disappears when I try to set some value by it.
What am I supposted to do?
I'll do appreciate any help.
5 Comments
Jan
on 17 Jan 2018
@Aleksandra: Set the Min and Max during the creation of the slider. Are you working with GUIDE? Then the OpeningFcn might be the best location - if the values for Min and Max are known already. If not, set them exactly in this part of the code, where they are created.
Adam
on 17 Jan 2018
If the user can change the min and max then do it in the callback of whatever UI component they use to do this, making sure you set the value at the same time.
Answers (1)
Stephen23
on 15 Jan 2018
Read the warning message:
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
When the value is outside of the min-max range then this warning is shown and the slider is not rendered (shown on screen). Clearly your value is outside of this range. If you are dynamically changing the min/max values then you need to consider the order in which you change them, and might need to change the value as well to ensure that it is always between min and max.
11 Comments
Stephen23
on 17 Jan 2018
Edited: Stephen23
on 17 Jan 2018
"I've thought that a position of sliders should be compatible with painted area like in the example above"
Yes, correct: you need to change some variables' values using the slider position values. These variable will be internal to your GUI somehere (exactly how depends on your GUI design).
"Thus, the limits of sliders should be the same as the domain on the graph."
No. The slider end limits do not need to change.
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!