[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sharing auxilary functions
From: |
Keith Goodman |
Subject: |
Re: Sharing auxilary functions |
Date: |
Fri, 17 Jun 2005 11:44:13 -0700 |
On 6/17/05, Søren Hauberg <address@hidden> wrote:
> John W. Eaton wrote:
> > On 17-Jun-2005, Søren Hauberg wrote:
> >
> > | I have a script that uses several auxilary functions, all in the same
> > | file. Now, I want to call these auxilary functions from another script.
> > | One way to accomplish this would be to put each auxilary function in
> > | seperate files, but that would create alot of files. Can I somehow
> > | create a file containing all the auxilary functions and then include
> > | them from the files that need the functions?
> >
> > I think you might be asking for the "private function" feature of
> > Matlab. I don't think there is a way to do that with Octave yet.
> Sounds a bit like it. However something simpler should do the trick. In
> C I would simply #include the file I need to share. Can I somehow parse
> a file containing functions without calling any of them?
I think I've seen this trick on the mailing list before.
Create a file called funcs that contains (you have to use endfunction):
xcsdfg = 1;
clear xcsdfg
function y = sum2(x)
y = sum(x);
endfunction
function y = prod2(x)
y = prod(x);
endfunction
Then in Octave:
$ octave
Octave 2.9.3 Forge 20050613
>> sum2([1 1])
error: `sum2' undefined near line 1 column 1
>> funcs
>> sum2([1 1])
ans = 2
>> prod2([1 1])
ans = 1
-------------------------------------------------------------
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
-------------------------------------------------------------