Jump to content

Octave help

xXImm0rtaLXx

I have a script file for Octave. I have functions written in the script file and i call them above the function declarations. But when i call them it says they're undefined, even though they're defined below. How do i fix this, so there wont be errors? Also, it all has to be in the script file

Link to comment
Share on other sites

Link to post
Share on other sites

It's probably interpreted sequentially. So, at the time that it gets to the function call, the interpreter has no clue what the function is. If everything is required to be in one file, then you have to define your functions before they are called. The better solution is to use a separate file for library functions and such, and have that in the path. See: https://octave.org/doc/v4.2.0/Function-Files.html

Link to comment
Share on other sites

Link to post
Share on other sites

Each function should be stored in their own .m file, which must have the same name as the function.

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, kuhnerdm said:

It's probably interpreted sequentially. So, at the time that it gets to the function call, the interpreter has no clue what the function is. If everything is required to be in one file, then you have to define your functions before they are called. The better solution is to use a separate file for library functions and such, and have that in the path. See: https://octave.org/doc/v4.2.0/Function-Files.html

 

I have now fixed it by putting "1;" as the first line and then putting functions below that, as the first line has no impact on anything, and the first line cant be a function, because octave will think it's a function file and not a script.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×