How can I control the values inside a drop-down menu within a GUI?

7 ビュー (過去 30 日間)
Blair Armstrong
Blair Armstrong 2019 年 4 月 13 日
コメント済み: Geoff Hayes 2020 年 4 月 24 日
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 件のコメント
Oliver Ferenczi
Oliver Ferenczi 2020 年 4 月 24 日
How could this be done on App Designer using app.DropDown?
Geoff Hayes
Geoff Hayes 2020 年 4 月 24 日
Perhaps app.DropDown.Items = {num2str((1:65)'}...though I haven't tested this myself.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by