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!

采纳的回答

Geoff Hayes
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
Geoff Hayes 2020-4-24
Perhaps app.DropDown.Items = {num2str((1:65)'}...though I haven't tested this myself.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Debugging and Analysis 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by