11.1 Introduction to Function and Script Files

There are seven different things covered in this section.

  1. Typing in a function at the command prompt.
  2. Storing a group of commands in a file — called a script file.
  3. Storing a function in a file—called a function file.
  4. Subfunctions in function files.
  5. Multiple functions in one script file.
  6. Private functions.
  7. Nested functions.

Both function files and script files end with an extension of .m, for MATLAB compatibility. If you want more than one independent functions in a file, it must be a script file (see Script Files), and to use these functions you must execute the script file before you can use the functions that are in the script file.

© 1996–2020 John W. Eaton
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://octave.org/doc/v6.3.0/Introduction-to-Function-and-Script-Files.html