FAQ: Difference between revisions

24 bytes added ,  11 June 2013
Line 399: Line 399:
First of all, make sure you understand [http://www.gnu.org/software/octave/doc/interpreter/Script-Files.html the difference between script files and function files]. If you want to execute a function defined in a file, just call the function like any other Octave function: <code>foo(arg1, arg2);</code>
First of all, make sure you understand [http://www.gnu.org/software/octave/doc/interpreter/Script-Files.html the difference between script files and function files]. If you want to execute a function defined in a file, just call the function like any other Octave function: <code>foo(arg1, arg2);</code>


To execute a script from within Octave, just type its name without the .m extension. Thus, if you have a script called <code>foo.m</code>, just type <code>foo</code> from within Octave to execute it. You have to make sure that the script is in your current path. Type <code>path</code> in Octave to see what this path is, and type <code>pwd</code> to see where you're currently standing (the current working directory is referred to as "." in the <code>path,</code>).
To execute a script from within Octave, just type its name without the .m extension. Thus, if you have a script called <code>foo.m</code>, just type <code>foo</code> from within Octave to execute it. You have to make sure that the script is in your current path. Type <code>path</code> in Octave to see what this path is, and type <code>pwd</code> to print the working directory (where you're currently standing). The current working directory is referred to as "." in the <code>path</code>.


If the script name has characters that are not valid for an Octave identifier, or if you do not want to use addpath to add the script's location to the current path, you can use the <code>run</code> function instead:
If the script name has characters that are not valid for an Octave identifier, or if you do not want to use addpath to add the script's location to the current path, you can use the <code>run</code> function instead: