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

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com