Global variable in octave

global m = 1;
function p = h()
  m
end
h()

      

I am trying to run this script, but I am getting this error:

'm' is undefined next to column 4 of column

Please tell me how can I use a variable from functions?

+3


source to share


1 answer


You have to declare var also global inside the function as described here: https://www.gnu.org/software/octave/doc/interpreter/Global-Variables.html



global m = 1;
function p = h()
  global m;
  m
endfunction
h()

      

+7


source







All Articles