开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜