pop up menu and slider....

5 visualizzazioni (ultimi 30 giorni)
Smith Steven
Smith Steven il 6 Giu 2013
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

Risposta accettata

Hugo
Hugo il 7 Giu 2013
Modificato: Hugo il 7 Giu 2013
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 Commenti
Hugo
Hugo il 7 Giu 2013
Modificato: Hugo il 7 Giu 2013
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 il 7 Giu 2013
Thanks a bunch Hugo :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by