Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
popup menu string in matlab gui?

Subject: popup menu string in matlab gui?

From: Martin Tegg

Date: 18 Jun, 2007 21:10:47

Message: 1 of 5

I am having trouble creating a Matlab Gui. I have created the gui
using GUIDE, and now I would like to populate a pop-up menu with an
array (A list of dates) from a seperate m-file. Using GUIDE, I have
created the pop-up menu, and have edited the string so that it is
blank. However, I am confused as to how to write the m-file code so
that the pop-up menu is populated with the dates. Can anyone help?

Subject: popup menu string in matlab gui?

From: Madincea Vasile

Date: 18 Jun, 2007 22:42:46

Message: 2 of 5

To select an item from the popup menu use:

    val = get(handlePOPUPMENU,'Value');
    string_list = get(Scenario_Lister,'String');
    selected_string = string_list{val};
    
    SelectedItem = val;

 To populate the popup menu use:

    string_list{1} = date1;
    string_list{2} = date2;
    ...etc...
    set(handlePOPUPMENU,'String',string_list);

 Hope it helps...

 Vasi

Subject: popup menu string in matlab gui?

From: Martin Tegg

Date: 18 Jun, 2007 22:57:20

Message: 3 of 5

Thanks for this. Can you tell me where to put the code? GUIDE has
automatically created two functions in the m-file. The first is
function POPUPMENU_Callback(hObject, eventdata, handles)

The second is:
function POPUPMENU_CreateFcn(hObject, eventdata, handles)

Do I put the populating code under the first one or the second one,
or somewhere else entirely?

Madincea Vasile wrote:
>
>
> To select an item from the popup menu use:
>
> val = get(handlePOPUPMENU,'Value');
> string_list = get(Scenario_Lister,'String');
> selected_string = string_list{val};
>
> SelectedItem = val;
>
> To populate the popup menu use:
>
> string_list{1} = date1;
> string_list{2} = date2;
> ...etc...
> set(handlePOPUPMENU,'String',string_list);
>
> Hope it helps...
>
> Vasi

Subject: popup menu string in matlab gui?

From: Madincea Vasile

Date: 18 Jun, 2007 23:16:19

Message: 4 of 5

normally, as long as you have the handle, you can do this anywhere,
but it is better to put it in the createFcn.
 Good luck !!!

Martin Tegg wrote:
>
>
> Thanks for this. Can you tell me where to put the code? GUIDE has
> automatically created two functions in the m-file. The first is
> function POPUPMENU_Callback(hObject, eventdata, handles)
>
> The second is:
> function POPUPMENU_CreateFcn(hObject, eventdata, handles)
>
> Do I put the populating code under the first one or the second one,
> or somewhere else entirely?
>
> Madincea Vasile wrote:
>>
>>
>> To select an item from the popup menu use:
>>
>> val = get(handlePOPUPMENU,'Value');
>> string_list = get(Scenario_Lister,'String');
>> selected_string = string_list{val};
>>
>> SelectedItem = val;
>>
>> To populate the popup menu use:
>>
>> string_list{1} = date1;
>> string_list{2} = date2;
>> ...etc...
>> set(handlePOPUPMENU,'String',string_list);
>>
>> Hope it helps...
>>
>> Vasi

Subject: popup menu string in matlab gui?

From: Martin Tegg

Date: 25 Jun, 2007 20:27:16

Message: 5 of 5

Thanks its working now. The trick was to get the string as a cell
array, not a double matrix

 

Madincea Vasile wrote:
>
>
> normally, as long as you have the handle, you can do this anywhere,
> but it is better to put it in the createFcn.
> Good luck !!!
>
> Martin Tegg wrote:
>>
>>
>> Thanks for this. Can you tell me where to put the code? GUIDE
> has
>> automatically created two functions in the m-file. The first
is
>> function POPUPMENU_Callback(hObject, eventdata, handles)
>>
>> The second is:
>> function POPUPMENU_CreateFcn(hObject, eventdata, handles)
>>
>> Do I put the populating code under the first one or the second
> one,
>> or somewhere else entirely?
>>
>> Madincea Vasile wrote:
>>>
>>>
>>> To select an item from the popup menu use:
>>>
>>> val = get(handlePOPUPMENU,'Value');
>>> string_list = get(Scenario_Lister,'String');
>>> selected_string = string_list{val};
>>>
>>> SelectedItem = val;
>>>
>>> To populate the popup menu use:
>>>
>>> string_list{1} = date1;
>>> string_list{2} = date2;
>>> ...etc...
>>> set(handlePOPUPMENU,'String',string_list);
>>>
>>> Hope it helps...
>>>
>>> Vasi

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us