Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How can I get variable/data from OpenMenu to Callback?

Asked by Hello kity on 31 Dec 2012

Hi,

i have a uigetfile in an openmenuItem. I want that 'filename' in the callback. I looked at couple FAQ wikis but really dont get it.

function OpenMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to OpenMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 [filename, pathname] = uigetfile({'*.xls'},'File Selector');
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.xls'},'File Selector'); %* this line should be defeleted after it works, currently it works but I want to select file from openmenu.*
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
     case 1
        Calculation(filename, handles) %other m-file
  end

0 Comments

Hello kity

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 31 Dec 2012

You cannot "return" a result from any Callback that has the object as its first argument (there are a small number of filtering callbacks such as zoom Post Action callbacks; they never pass in the object as the first argument.)

So instead see: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F

0 Comments

Walter Roberson

Contact us