Effacer les filtres
Effacer les filtres

Matlab update popmenu string

3 vues (au cours des 30 derniers jours)
Ali
Ali le 12 Oct 2022
Commenté : Ali le 13 Oct 2022
Hi,
I have a gui wich has a lot of menus associated with radiobuttons. Menus or popmenus will be available to edit or select only if the radiobuttons next to them is selected.
Among these menus i have 2 popmenus associated to a radiobutton. In the first popmenu i have set up in the string 3 different choices and if i take choice 1 and 2 the second popmenu will propose a string with 5 choice. But if i select choice 3 in the second popmenu i have only it will change the string of the popmenu 2 and all the proposition will be different.
To do that i have a function which works but the only problem is that to see the change of string in the popmenu 2 i need to unselect and select again the radiobutton. Is there a way to refresh the popmenu 2 choices when i change the selection in popmenu 1?
Here is the function that allow to change the choices in the popmenu 2 :
function Scr519(h)%h contains the two popmenus
enable(h)%Enable both popmenus
x=get(h(2),'Value');%get the selected element in the popmenu2
switch get(h(1),'Value')% get the selected element in the popmenu1
case {1,2}% The selected element in popmenu1 is the first or second in order
if (x<1)||(x>5),x=1;end %Set the selected element of the popmenu2 to the first element.
ch='Iscr<20|20<Iscr<50|50<Iscr<100|100<Iscr<1k|1000<Iscr';%ch is the popmenu2 string
case 3
if (x<1)||(x>3),x=1;end
ch='Iscr<25|25<Iscr>50|Iscr>=50';
otherwise
error(kverranorm(6))
end
set(h(2),'String',ch,'Value',x)%Update the string of the popmenu2 and it's selected element
I put in an exemple file containing the gui and the function (until line 179 it's the gui then we have the function that enable/disable the menus when the radiobutton next to them is selected, then we have this function)
  6 commentaires
Rik
Rik le 13 Oct 2022
Why do you think you need to use a while loop? What do you mean by being stuck?
I'm used to using h to contain the guidata struct, so seeing it being used as an array of handles is a bit confusing.
What you need to do is gather all relevant settings and determine what options should exist in your second dropdown and which should be currently sellected. Your current code does that.
Perhaps you should put a breakpoint at the beginning of your function and step through the code line by line.
Your comments are already quite an improvement, although I would suggest putting them on separate lines. Your initial goal should be to have about half of the characters in a function to be documentation. That is probably too strict, but if you aim for 50%, you'll end up at a more reasonable ratio. Remember that you need to understand what you did in 6 months as well. I have absolutely no clue what I did in my code before I started rigorous commenting. From that point onward I understand what I did, even if I haven't looked at the code for years.
Ali
Ali le 13 Oct 2022
ok thank you for your advise i will do that.
And by being stuck i mean that it will enable the 2 popmenus but after that it will just constantly return the value of x1 = 1 and do nothing else.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Produits


Version

R2012a

Community Treasure Hunt

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

Start Hunting!

Translated by