Handling Slider in GUI
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
JA
am 18 Aug. 2016
Beantwortet: Andres Castillo Bermudez
am 28 Nov. 2018
I want my slider to increase in steps of 1, no fractions allowed, not when it's being dragged. Not even when i click on increase/decrease button.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (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
set(handles.slider2, 'Max',10);
set(handles.slider2, 'Min', 1);
set(handles.slider2, 'SliderStep' , [1,1] );
sliderValue = get(handles.slider2,'Value');
set(handles.edit2,'String',sliderValue)
even though i have it 1,1. it doesn't work according to what i want and i have kept the minimum as 1, so when i click on increase button. it increases '0.01' and i get this error:
Warning: slider control can not have a Value outside of Min/Max range
Control will not be rendered until all of its parameter values are valid
Warning: slider control can not have a Value outside of Min/Max range
Control will not be rendered until all of its parameter values are valid
Warning: slider control can not have a Value outside of Min/Max range
Control will not be rendered until all of its parameter values are valid
and the slider disappears. Not sure where i am going wrong
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 18 Aug. 2016
Setting the min and max and sliderstep should be done at the time the slider is created, such as in slider2_CreateFcn
For the other part of your question see https://www.mathworks.com/matlabcentral/answers/216723-how-can-i-force-a-slider-uicontrol-object-in-guide-to-move-in-discrete-steps
5 Kommentare
Weitere Antworten (1)
Andres Castillo Bermudez
am 28 Nov. 2018
I Round the number with the 'round function'
coff=round(get(hObject,'value')); %round the number
set(handles.lpfDisplay,'String',num2str(coff)); %display the number on a text box
I use it for a guitar effect on Matlab.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!