Clear Strings in a PopUpMenu

1 visualizzazione (ultimi 30 giorni)
Franco
Franco il 10 Lug 2014
Modificato: Ben11 il 10 Lug 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.

Risposta accettata

Ben11
Ben11 il 10 Lug 2014
Modificato: Ben11 il 10 Lug 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'));

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