10
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?

2
  • 1
    Please read the documentation. This addressed exactly in one of the very first examples. Commented Dec 10, 2014 at 19:53
  • possible duplicate of Declaring a global variable in MATLAB -this is a Matlab-tagged question, but the solution is identical for Octave. Commented Dec 10, 2014 at 19:54

1 Answer 1

15

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() 
Sign up to request clarification or add additional context in comments.

2 Comments

How to change the global variable from the function then?
like you would change any other var: assign a new value to it. What have you tried so far?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.