How can I control the values inside a drop-down menu within a GUI?
조회 수: 8 (최근 30일)
이전 댓글 표시
As part of a larger GUI I'm making, I want the user to be able to select a value between 1 and 65 from a dropdown menu to select the channel they would like to view for an electorde array. I've already made everything in guide and the drop down is filed under the 'voltageselect_Callback'.
But I'm having trouble making the numbers between 1 and 65 actually appear, here's what I have.
% --- Executes on selection change in voltageselect.
function voltageselect_Callback(hObject, eventdata, handles)
% hObject handle to voltageselect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
contents = cellstr(get(hObject,'String'));
selected_item = contents{get(hObject,'Value')};
plot(chunked_data(:,selected_item),'parent',handles.axes2);
% Hints: contents = cellstr(get(hObject,'String')) returns voltageselect contents as cell array
% contents{get(hObject,'Value')} returns selected item from voltageselect
voltageoptions = [1:65];
handles.voltageselect = voltageoptions;
guidata(hObject, handles);
I'm not sure how to correlate the GUI to look at the array I've made and display it and I seem lost looking at the doc for uicontrol.
Thank you greatly for any help!
댓글 수: 0
채택된 답변
Geoff Hayes
2019년 4월 13일
Blair - you need to populate the drop-down control elsewhere in the code (not in the callback that would fire after the user has selected a value). Populating the control can be done in the OpeningFcn of your GUI as
function myGui_OpeningFcn(hObject, eventdata, handles, varargin)
% whatever other code you have
% populate the drop-down
set(handles.popupmenu2, 'String', num2str((1:65)'));
댓글 수: 3
Geoff Hayes
2020년 4월 24일
Perhaps app.DropDown.Items = {num2str((1:65)'}...though I haven't tested this myself.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!