Create a popup menu based on dynamic data
Show older comments
Hi there
I wonder if someone can help me with this as I am new to Matlab. I have created a gui in matlab using guide and have added a popup button but I want the popup menu contents to vary based on a list created stored in a string. e.g. I have a file called ci which contains 'data', 'door', 'mug' in a list. I want this to be used in the popup menu. This list will vary so i need it to be dynamic so if the list also includes 'phone' etc it still works. Can anyone help? The code is given below
% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu4
% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
Accepted Answer
More Answers (1)
Sean de Wolski
on 9 Aug 2011
Where is the string stored? Is it in an edit box?
inside the callback:
S = get(handles.text_box_of_choice,'string');
msgbox(S);
Please be more specific and perhaps show an image of your gui and popup.
Categories
Find more on System Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!