help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: self-contained Octave scripts


From: John W. Eaton
Subject: Re: self-contained Octave scripts
Date: Fri, 4 Aug 2000 10:25:55 -0500 (CDT)

On  4-Aug-2000, Kai Habel <address@hidden> wrote:

| First, make sure that your scripts works within octave. So all your
| functions must reside in its own files. These files must be in octave's 
| LOADPATH.

You can do that, but it is not absolutely necessary.  For example, the
following works fine with Octave 2.0.x:

  #! /usr/local/bin/octave -q

  ### The following statement is here to prevent Octave from
  ### misinterpreting this file as a one-function only M-file if called
  ### from the Octave command line.

  1;

  function foo (x)
    bar (x);
  endfunction

  function bar (x)
    printf ("%sŠÜn", x);
  endfunction

  puts ("This Octave was invoked with the following arguments:ŠÜn");
  for i = 1:nargin
    foo (argv(i, :));
  endfor

The functions must be defined before they are acutally called (note
that the reference to the function bar inside the function foo before
bar is defined is not the same as calling bar).

After saving the above in foobar.m and making it executable:

  $ ./foobar.m one fish two fish red fish blue fish
  This Octave was invoked with the following arguments:
  one 
  fish
  two 
  fish
  red 
  fish
  blue
  fish

jwe



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]