我正在使用matlab gui,我想根据另一个滑块的值(slider1)更改滑块的最大值(slider2)。 我的公式很简单。但我不知道如何更改滑块值。这是我的滑块代码:
taper = get(hObject,'value') ; %slider 1
set(handles.texttaper,'string',num2str(taper)) ;
guidata(hObject,handles) ;
rs = get(hObject,'value') ; %slider 2
set(handles.textrs,'string',num2str(rs)) ;
guidata(hObject,handles) ;
答案 0 :(得分:0)
如果要通过slider1更改slider2的最大值,则必须在slider1的回调函数中设置slider2 'Max'
的值。我给你举了一个小例子:
% --- Executes on slider1 movement.
function slider1_Callback(hObject, eventdata, handles)
set(handles.slider2,'Max',get(hObject,'Value')) %This line does the magic!!
% This function creates slider 1
function slider1_CreateFcn(hObject, eventdata, handles)
set(hObject,'Min',0,'Max',10)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider2 movement.
function slider2_Callback(hObject, eventdata, handles)
set(handles.text2,'string',get(hObject,'Value'))
% This function creates slider 2
function slider2_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes during object creation, after setting all properties.
function text2_CreateFcn(hObject, eventdata, handles)
我创建两个滑块。 Slider1的范围在0到10之间。其回调函数设置slider2的'Max'
值。 Slider2的值显示在文本框中。
希望有帮助!