GUI--how to program two sliders to be dependent on each other

6 次查看(过去 30 天)
I have made a gui with two sliders that I need to be dependent on each other. I have an equation that relates them (slider1=slider2/.156). I want to be able to move either slider and have the other slider move automatically based on this formula.
I have not programmed the sliders to work correctly, so if anything, I would love some help getting my sliders programmed.
thanks!

采纳的回答

Paulo Silva
Paulo Silva 2011-6-6
Suppose your are using GUIDE, on the slider2 callback
set(handles.slider1,'value',get(handles.slider2,'value')/.156)
if not using GUIDE just replace handles.slider1 by the slider1 handle
Simple example, move the slider of the bottom and watch the one in the top, please be carefull with the values.
hf=figure;
sh2 = uicontrol(hf,'Style','slider',...
'Max',1,'Min',0,'Value',0.1,...
'SliderStep',[0.05 0.2],...
'Position',[30 20 150 30],...
'Callback','set(sh1,''value'',get(sh2,''value'')/.156)');
sh1 = uicontrol(hf,'Style','slider',...
'Max',10,'Min',0,'Value',5,...
'SliderStep',[0.05 0.2],...
'Position',[30 90 150 30]);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by