필터 지우기
필터 지우기

How to populate a popup menu GUI from a structure list

조회 수: 6 (최근 30일)
Andrew Paulsen
Andrew Paulsen 2017년 5월 25일
댓글: Andrew Paulsen 2017년 5월 26일
Struggling to get data into my popup menus to then select desired inputs to generate an output.
Here is my code... I have a push button that creates a MEX file and converts sie files to mat and generates a structure. Then I want three popup menus to select three channels to then solve. How do I populate my generated data1.ChannelName in the popup menus and then input those selections into variables?
% --- Executes on selection change in lat1.
function lat1_Callback(hObject, eventdata, handles)
% hObject handle to lat1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
items = get(hObject, 'String', data1.ChannelName);
index_selected = get(hObject, 'Value');
item_selected = items{index_selected};
display(item_selected);
% Hints: contents = cellstr(get(hObject,'String')) returns lat1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from lat1
% --- Executes during object creation, after setting all properties.
function lat1_CreateFcn(hObject, eventdata, handles)
% hObject handle to lat1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject,'String',data1.ChannelName);
% 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

채택된 답변

Image Analyst
Image Analyst 2017년 5월 25일
편집: Image Analyst 2017년 5월 25일
You can create the 3 popup menus with GUIDE. You can enter the strings you want them to display also in GUIDE, which is what I think you might mean by "get data into my popup menus". Double click the popup in GUIDE, which brings up the Property Inspector, and edit the String property to enter in the text you want it to display.
Then, in any callback function, you can get the item number that was selected by the user at run-time for each popup like this:
popupValue1 = handles.popup1.Value;
popupValue2 = handles.popup2.Value;
popupValue3 = handles.popup3.Value;
I don't know what "data1.ChannelName" is, or if there are 3 of them. Maybe you want to put the indexes of the popups into the ChannelName fields of 3 different structures. If so, you can do
data1.ChannelName = handles.popup1.Value;
data2.ChannelName = handles.popup2.Value;
data3.ChannelName = handles.popup3.Value;
popup1, popup2, and popup3 are the "tag" properties of the popups that you'll see when you double click the popup in GUIDE, which brings up the Property Inspector.
  댓글 수: 1
Andrew Paulsen
Andrew Paulsen 2017년 5월 26일
Just to clarify... I populate the popup with the _CreateFcn and I store what was selected in the _Callback?
I tried using Matlab's basic example on populating popups to display Red,Green,Blue in the popup, though I couldn't get even that to work for some reason.
Has yet to click yet on how to retrieve and display the data within GUIDE.
I am using 2015b...does Application Developer make it any eaiser?
Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by