MATLAB: Combining Edit Text & Popup Menu Code in a Popup Menu Callback

callbackguiguideMATLABmatlab gui

Hi, just wondering if there's any way I can combine "edit text" and "popup menu" codes into a push button? Capture.JPGIs there any way the codes (from the "Edit Text" and "Popup Menu" run together when I run the push button?
Thanks in advance!

Best Answer

Regina - in the callback for the push button, use the handles structure to get access to the edit texet control and the pop-up menu. Use the get function to get the text or selection (from the menu). For example, the callback for your button might be
function pushbutton1_Callback(hObject, eventdata, handles)
% get the text value from the edit text control
numberOfCubes = str2double(get(handles.edit1, 'String'));
% get the number of dimensions
popupMenuItems = get(handles.popup1, 'String'); % assume cell array of strings for list of dims
numberOfDimensions = str2double(popupMenuItems{get(handles.popup1,'Value')});
end
Related Question