Effacer les filtres
Effacer les filtres

Create a popup menu based on dynamic data

5 vues (au cours des 30 derniers jours)
Said
Said le 9 Août 2011
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

Réponse acceptée

Said
Said le 9 Août 2011
Hi I spoke to someone and eventually figured it out so thank for your reply anyway. The data is stored in a cell array and i had a push button to select the data. But the problem was in defining the string to be used and not putting the correct thing in the callback part of the code. The code below is what seems to work.
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Extract curve information
ci = handles.wlog.curve_info(2:end, 1);
handles.ci = ci;
% Update handles structure
guidata(handles.figure1, handles);
% Set popupmenu1 string for list
set(handles.popupmenu1,'string',ci)
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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 popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
%data = evalin('base','ci');
data = guidata(handles.figure1);
set(hObject, 'String', data.handles.ci)
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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

Plus de réponses (1)

Sean de Wolski
Sean de Wolski le 9 Août 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.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by