Initialize contents of popupmenu in GUIDE

I am writing a GUI in GUIDE which contains a popup menu. In the Property Inspector the String property is empty. The contents of the menu must be filled during execution and are assigned values from a structure as such:
a = {AlertFD.name};
set(handles.popupmenu1, 'String', a);
and the user input is assigned to b:
b = get(handles.popupmenu1, 'Value');
The problem occurs when I run the GUI: when I first click on the menu, I see an empty cell. I click on the empty cell and then the first element of cell a is shown and automatically passed as user input to b , even though I do not wish to select it.
Any solutions? Thanks, George

 Réponse acceptée

Image Analyst
Image Analyst le 21 Sep 2013

0 votes

You need to set both the string and the value in the OpeningFcn function (if that doesn't work, then put it in the OoutputFcn function). Since you did not set the value (you only retrieved it) no item will be selected/shown when your GUI starts up.

5 commentaires

George's reply moved from an independent "Answer" to a "Comment" here:
Thank you for the reply. I achieved what I was looking for by setting only the String property inside the OutputFcn. In addition, I wish to reset the String values of the popupmenus with the push of a button so I can make new user inputs. I am setting the String property within the button's callback as such:
set(handles.popupmenu1, 'String', handles.a);
However, the popupmenus are reappearing with the previous selections.
Image Analyst
Image Analyst le 24 Sep 2013
What is handles.a? Is it a cell array of strings?
Image Analyst
Image Analyst le 24 Sep 2013
Modifié(e) : Image Analyst le 24 Sep 2013
Georges "Answer" moved AGAIN to here because it is not an actual Answer to his original question, but actually a comment on my reply.
handles.a is indeed a cell array of strings which is defined in the OpeningFcn.
Well something somewhere is changing it. You might have to step through your code calling
contents = get((handles.popupmenu1, 'String')
at each step to see what changes it.
George
George le 24 Sep 2013
Modifié(e) : George le 24 Sep 2013
I've found out that the problem was not the 'String' property; instead the problem was caused by the 'Value' property. Apparently this was kept in the previously assigned value. I am setting it manually within the Callback and it works fine now. Thanks for the help, much appreciated!
(Apologies for misusing the reply text boxes)

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by