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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Ag. de 2016

0 votos

Setting the min and max and sliderstep should be done at the time the slider is created, such as in slider2_CreateFcn

5 comentarios

JA
JA el 18 de Ag. de 2016
Editada: JA el 18 de Ag. de 2016
I tried to setting it in slider2_CreateFcn. But I am getting this error: Attempt to reference field of non-structure array.
Attempt to reference field of non-structure array.
Error in gui>slider2_CreateFcn (line 210)
set(handles.slider2, 'Max',10);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in gui (line 44)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)gui('slider2_CreateFcn',hObject,eventdata,guidata(hObject))
Error using struct2handle
Error while evaluating uicontrol CreateFcn
Will check that link, Thank you!
Walter Roberson
Walter Roberson el 18 de Ag. de 2016
set(hObject, 'Max', 10, 'Min', 1);
JA
JA el 18 de Ag. de 2016
Still doesn't work.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject, 'Max', 10, 'Min', 1);
This is where i set it.
I get the below 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
> In openfig at 135
In gui_mainfcn>local_openfig at 286
In gui_mainfcn at 234
In gui at 44
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
Walter Roberson
Walter Roberson el 18 de Ag. de 2016
You should give it a Value in slider2_CreateFcn as the default is 0
JA
JA el 19 de Ag. de 2016
Thanks for your reply. Can you help me with the slider steps. I have set it as
set(hObject, 'SliderStep' , [1/9,1/9] );
In the CreateFcn, but only when i use the increase/decrease button, it works when i drag the slider. it does not work

Iniciar sesión para comentar.

Más respuestas (1)

Andres Castillo Bermudez
Andres Castillo Bermudez el 28 de Nov. de 2018

1 voto

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.

Categorías

Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

JA
el 18 de Ag. de 2016

Respondida:

el 28 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by