[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to share variables between functions
From: |
Chris Wagner |
Subject: |
Re: How to share variables between functions |
Date: |
Tue, 22 May 2007 13:42:09 -0700 (PDT) |
John W. Eaton wrote:
>
>
> With Octave 2.9.10, you can write
>
> function y = f (x)
> y = quad (@(t) g (x, t), 0, 1);
> endfunction
> function y = g (x, t)
> y = t*x;
> endfunction
>
> jwe
>
>
I may be missing something, but I can't seem to get the above anonymous
function passing to work between multiple .m files.
This seems to work (everything in one .m file):
f2.m:
function y = f2(x)
y = f3(@(t) g(x,t), 1, 2);
function y = g(x,t)
y = t*x;
function y = f3(infunc, a, b)
y = infunc(a) + infunc(b);
Then on the command line,
octave:5> f2(5)
ans = 15
But with the function f3 in another .m file in the same directory:
f2.m:
function y = f2(x)
y = f3(@(t) g(x,t), 1, 2);
function y = g(x,t)
y = t*x;
f3.m:
function y = f3(infunc, a, b)
y = infunc(a) + infunc(b);
And running on the command line:
octave:7> f2(5)
error: `g' undefined near line 2 column 15
error: called from `?unknown?'
error: evaluating binary operator `+' near line 2, column 20
error: evaluating assignment expression near line 2, column 8
error: called from `f3' in file `/home/cwagner/octave-test/f3.m'
error: evaluating assignment expression near line 2, column 5
error: called from `f2' in file `/home/cwagner/octave-test/f2.m'
octave:7>
Is this the expected behavior? I'm using Octave 2.9.11.
Chris
--
View this message in context:
http://www.nabble.com/How-to-share-variables-between-functions-tf3513067.html#a10752161
Sent from the Octave - General mailing list archive at Nabble.com.
- Re: How to share variables between functions,
Chris Wagner <=