MATLAB Answers

0

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

Asked by Blair Armstrong on 13 Apr 2019
Latest activity Commented on by Blair Armstrong on 13 Apr 2019
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 Comments

Sign in to comment.

Products


Release

R2018a

1 Answer

Answer by Geoff Hayes
on 13 Apr 2019
 Accepted Answer

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)'));

  1 Comment

Ah! Thank you so much, and code I wanted to execute after selection would go in the callback!

Sign in to comment.