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

3 ビュー (過去 30 日間)
Brittany
Brittany 2011 年 6 月 6 日
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 Center および File ExchangeDebugging and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by