Declaring a global variable in MATLAB

后端 未结 3 929
暗喜
暗喜 2020-11-28 13:29

Is there a way to declare global variables in MATLAB?

Please don\'t respond with:

global x y z;

Because I can also read the help fi

3条回答
  •  囚心锁ツ
    2020-11-28 13:42

    You need to declare x as a global variable in every scope (i.e. function/workspace) that you want it to be shared across. So, you need to write test1 as:

    function test1()
      global x;
      x = 5;
    end
    

提交回复
热议问题