You are on page 1of 5

Vote

Createapopupmenubasedondynamicdata
AskedbySaidon9Aug2011
AcceptedAnswerbySaid
51views(last30days)

Hithere

IwonderifsomeonecanhelpmewiththisasIamnewtoMatlab.Ihavecreatedaguiinmatlabusingguideand
haveaddedapopupbuttonbutIwantthepopupmenucontentstovarybasedonalistcreatedstoredinastring.
e.g.Ihaveafilecalledciwhichcontains'data','door','mug'inalist.Iwantthistobeusedinthepopupmenu.
Thislistwillvarysoineedittobedynamicsoifthelistalsoincludes'phone'etcitstillworks.Cananyonehelp?
Thecodeisgivenbelow

%Executesonselectionchangeinpopupmenu4.
functionpopupmenu4_Callback(hObject,eventdata,handles)
%hObjecthandletopopupmenu4(seeGCBO)
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Hints:contents=cellstr(get(hObject,'String'))returnspopupmenu4contentsascellarray
%contents{get(hObject,'Value')}returnsselecteditemfrompopupmenu4

%Executesduringobjectcreation,aftersettingallproperties.
functionpopupmenu4_CreateFcn(hObject,eventdata,handles)
%hObjecthandletopopupmenu4(seeGCBO)
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesemptyhandlesnotcreateduntilafterallCreateFcnscalled

%Hint:popupmenucontrolsusuallyhaveawhitebackgroundonWindows.
%SeeISPCandCOMPUTER.
ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

0Comments
Tags
popupmenu

Products
Noproductsareassociatedwiththisquestion.

RelatedContent

2Answers

Vote
0
Link
AnswerbySaidon9Aug2011
Acceptedanswer

HiIspoketosomeoneandeventuallyfigureditoutsothankforyourreplyanyway.Thedataisstoredinacell
arrayandihadapushbuttontoselectthedata.Buttheproblemwasindefiningthestringtobeusedandnot
puttingthecorrectthinginthecallbackpartofthecode.Thecodebelowiswhatseemstowork.

%Executesonbuttonpressinpushbutton3.
functionpushbutton3_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton3(seeGCBO)
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Extractcurveinformation
ci=handles.wlog.curve_info(2:end,1);
handles.ci=ci;
%Updatehandlesstructure
guidata(handles.figure1,handles);

%Setpopupmenu1stringforlist
set(handles.popupmenu1,'string',ci)

%Executesonselectionchangeinpopupmenu1.
functionpopupmenu1_Callback(hObject,eventdata,handles)
%hObjecthandletopopupmenu1(seeGCBO)
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Hints:contents=cellstr(get(hObject,'String'))returnspopupmenu1contentsascellarray
%contents{get(hObject,'Value')}returnsselecteditemfrompopupmenu1
%data=evalin('base','ci');
data=guidata(handles.figure1);
set(hObject,'String',data.handles.ci)


MATLABAnswers
%Executesduringobjectcreation,aftersettingallproperties.
functionpopupmenu1_CreateFcn(hObject,eventdata,handles)
%hObjecthandletopopupmenu1(seeGCBO)
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesemptyhandlesnotcreateduntilafterallCreateFcnscalled

%Hint:popupmenucontrolsusuallyhaveawhitebackgroundonWindows.
%SeeISPCandCOMPUTER.
ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

0Comments

Vote
1
Link
AnswerbySeandeWolskion9Aug2011
Whereisthestringstored?Isitinaneditbox?

insidethecallback:

S=get(handles.text_box_of_choice,'string');
msgbox(S);

Pleasebemorespecificandperhapsshowanimageofyourguiandpopup.

0Comments

MATLABAnswers

MATLABandSimulinkresourcesforArduino,LEGO,andRaspberryPi

Learnmore

DiscoverwhatMATLABcandoforyourcareer.
Opportunitiesforrecentengineeringgrads.

ApplyToday

MATLABAcademy
NewtoMATLAB?

LearnMATLABtoday!
19942016TheMathWorks,Inc.

MATLABAnswers

You might also like