How to populate a popup menu GUI from a structure list
조회 수: 6 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!