Expert Answer:
s:
Wherever a global variable is going to be accessed in your code (say, different script files, functions etc.), it should be declared as such: global globalVariable;
. Eg.:
function myGUI_OpeningFcn(hObject, eventdata, handles, varargin)
global myGlobalVar;
myGlobalVar = [...]
[...]
end
function btnWriteFile_Callback(hObject, eventdata, handles)
global myGlobalVar;
if myGlobalVar [...]
[...]
end
Notice that in both functions the variable is declared as global in order for them to access it.