2016-08-19 5 views
0

슬라이더를 만들 때 슬라이더의 최소 및 최대 값을 설정하려고합니다. 슬라이더 단계 및 기본 최소 및 최대 값

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); 

하지만 GUI가 열릴 때, 그것을 던져 오류와 슬라이더가

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 

사라지고 난 때 증가/감소 드러그 경우에도 1과 슬라이더 단계를 설정하려고 또는 AM 버튼이 사용됩니다.

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, 'SliderStep' , [1/9,1/9]); 
sliderValue = get(handles.slider2,'Value'); 
set(handles.edit2,'String',sliderValue) 

단위 단계는 내가

답변

1

당신은 Value의를 지정하는 것이 좋습니다 내가 잘못 가고 위치에 대한 단서가 도움이 될 것입니다 maxvalue-minvalue

을 선택해야하기 때문에이 1/9을 chosed했다 귀하의 CreateFcn을 기본값으로 사용하기 때문에, 값은/Max 범위를 벗어나서 이 렌더링되지 않으므로 uicontrol이 렌더링되지 않습니다. 당신은 항상 (드래그도) 정수로 슬라이더 값을 강제하려는 경우 또한, 나는 또한

function slider2_CreateFcn(hObject, eventdata, handles) 
    if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 
     set(hObject,'BackgroundColor',[.9 .9 .9]); 
    end 

    set(hObject, 'Max', 10, 'Min', 1, 'Value', 1, 'SliderStep', [1/9 1/9]); 

뿐만 아니라 CreateFcn 내에서 SliderStep을 설정하는 것이 좋습니다 것입니다, 당신은 내부의 Value 속성을 반올림 할 수 있습니다 슬라이더의 콜백

function slider2_Callback(hObject, eventdata, handles) 
    value = round(get(handles.slider2, 'Value')); 
    set(handles.slider2, 'Value', value); 

    % Do whatever you need to do in this callback 
end