MATLAB: How to pass a value out of a GUI when button is pressed? The value must be available to another m file

guidematlab gui

Hello,
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.
Thanks,
Brian

Best Answer

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.
eg.
m-file 1
global BND_CDN
...
in m-file 2:
global BND_CDN
a = BND_CDN etc.