From help-octave-request at bevo dot che dot wisc dot edu Fri Sep 14 10:14:12 2001 Subject: embedding function From: "John W. Eaton" To: "Q. Peter He" Cc: help-octave at bevo dot che dot wisc dot edu Date: Fri, 14 Sep 2001 10:13:56 -0500 On 14-Sep-2001, Q. Peter He wrote: | Hi all, | | I'm trying to write a code which deals with embedding functions: | | Here is my code test.m | | #!/usr/bin/octave -qH | | type=str2num(nth(argv,1)); | | if type == 1 | test1(argv); | else | test2(argv); | endif | | function test1(...) | argv | endfunction | | function test2(...) | argv | endfunction | | When I tried to run this code, I got the following message: | | error: 'test1' undefined near line 4 column 3 | error: evaluating index expression near line 4, column 3 | error: evaluating if command near line 3, column 1 | | I heard that Octave actually support such type of embedding functions. | Should I define a main function some where? Define before invoking and make sure the first non-comment token in the file is not the keyword "function". The following should work. #!/usr/bin/octave -qH 1; # not a function file. function test1(...) argv endfunction function test2(...) argv endfunction type=str2num(nth(argv,1)); if type == 1 test1(argv); else test2(argv); endif jwe ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------