Declare variables for the entire scope in Matlab
I'm been working on a GUI in which many functions use the object.
Currently, this object is declared as global variable i开发者_运维问答n each of the subfunction in the gui.
This object is also used by timers so direct reference fun1(myobject)
not always working right.
function fun1
global myobject
...
function fun2
global myobject
...
I wanted to know if there's a smarter way of declaring this variable for the entire scope of the GUI m-file. I've tried declaring it outside the functions but it didn't work.
myobject = 1
function fun1
...
function fun2
...
Use nested sub-functions:
function myGui
a = 5;
f1();
f2();
function f1 ()
disp (a)
end
function f2 ()
disp (a)
end
end
精彩评论