pop up menu and slider....

2 次查看(过去 30 天)
Smith Steven
Smith Steven 2013-6-6
Hi all. I am new to GUIDE. I have made a pop up menu with four options. Now i want to make a slider that has values ranging from 5 to 12. What i want to do is if i select Option 1 from Pop up, slider value shall lie between 5 and 6. If Option 2, slider should fall in 7-9 and so on...... please help if anybody has idea how to do it..... Thanks

采纳的回答

Hugo
Hugo 2013-6-7
编辑:Hugo 2013-6-7
Hopefully this helps:
1) Save the handles of the ui elements. Suppose that hpopup and hslider are the handles of the pop up menu and the slider, respectively.
2) When you define the pop up menu, add in the list of arguments:
...,'Callback',@modslider...
@modslider is a function that will be call whenever you choose a different option in the pop up menu. The name modslider is just a name, you can change it as you wish.
3) Define a function
function modslider(hcall,eventdata)
end
hcall contains the handle of the ui that called it. From there you can get what option is active using
get(hcall,...)
and set the appropriate value of the slider using
set(hslider,...)
Best regards
  3 个评论
Hugo
Hugo 2013-6-7
编辑:Hugo 2013-6-7
I apologise for the misspelling in the name of the function. Now I have corrected it.
The function can be a nested function, or in a different file, as long as matlab can find it.
It should be something like this
function modslider(hcall,eventdata)
valpopup=get(hcall,...); %here you get the value of the property of the pop up menu, be it the index of the chosen item or anything else.
switch valpopup
case ...: set(hslider,....); % here you set the value of the slider that you want to modify according to the value in the pop up menu.
case ...: set(hslider,'Min',5,'Max',12);
end
end
You can find how to set the values of the slider and other uicontrols in the documentation of Matlab. Just write uicontrol.
Smith Steven
Smith Steven 2013-6-7
Thanks a bunch Hugo :)

请先登录,再进行评论。

更多回答(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