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

19 views (last 30 days)
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!

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!