To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016
I am making a GUI which adds rows to a matrix in one part. I want the matrix to be available to another m-file when I press another button (export). I've been looking at this for two weeks and can't figure it out. What is the syntax to make this matrix available to another function? eg x = function (y, exported_matrix). The normal [export_matrix] =Callback_pushbutton(....) doesn't work for GUI's. Can someone explain this? Sorry, this is probably basic but I can't see by any examples how this would work with my own GUI.
No products are associated with this question.
For reference to anyone with the same problem: Use global. It may or not be bad programming practivce but it works. global has to be stated in BOTH m files.
global BND_CDN ...
in m-file 2:
global BND_CDN a = BND_CDN etc.
Did you ever stumble upon the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
Assume your GUI has the tag-property 'MyGUI' (a more meaningful tag is recommended...). Then the store the matrix in the handles struct inside the GUI:
handles.matrix = rand(10, 10); % Or how ever you define the elements guidata(hObject, handles); % 1st argument: handle of the current object
Now obtain the matrix from your external M-file:
function theExternalFunction guiHandle = findobj(allchild(0), 'flat', 'tag', 'MyGUI'); guiHandles = guidata(guiHandle); matrix = guiHandles.matrix; ...
guidata() is a wrapper for setappdata() and getappdata(). Some exceptions should be caught by tests, e.g. if the guiHandle cannot be found because the GUI has been closed before, etc.