Andrew
Andrew

Reputation: 419

global variable in octave

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

I'm trying to run this script, but I get this error:

'm' undefined near line 4 column 3

Say me please, how I can use the variable from functions?

Upvotes: 10

Views: 8941

Answers (1)

Andy
Andy

Reputation: 8091

You have to declare the 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()

Upvotes: 14

Related Questions