Clear Strings in a PopUpMenu

1 vue (au cours des 30 derniers jours)
Franco
Franco le 10 Juil 2014
Modifié(e) : Ben11 le 10 Juil 2014
So I have built a GUI with a popupmenu. Say that the strings in the popupmenu are {'1','2','3'}. In this same GUI, I have a button that is supposed to repopulate the strings in the popupmenu. Say, that I push the button and instead of populating the popupmenu with {'1','2','3'}, I push the button and I want to populate it with {'5','4'}. The result is now a popupmenu with strings {'5','4','3'}. What I want to know is either 1. How do I clear the strings in the popupmenu before populating it, or 2. How do I get rid of the entry (the last 3 in this case) that is unwanted. Thanks in advance for your help.

Réponse acceptée

Ben11
Ben11 le 10 Juil 2014
Modifié(e) : Ben11 le 10 Juil 2014
You can control what appears in the popup menu by using a cell array containing the strings you want to display.
For instance you don't have to clear the existing popup menu's content but rather replace it with what you want:
MyStrings = {'5' '4'};
set(handlesToPopupMenu,'String',MyStrings);
and it should update correctly. If on the other hand you want to retrieve the content of the popup menu as a cell array, use this:
MyStrings = cellstr(get(handlesToPopupMenu,'String'));

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by