Setting the variable range of Slider in GUI
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jan
am 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
am 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.
Antworten (1)
Stephen23
am 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 Kommentare
Stephen23
am 17 Jan. 2018
Bearbeitet: Stephen23
am 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.
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!