[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Thu, 16 Nov 2006 16:09:13 +0100
I just tried to use anonymous functions, but they do not seem to work
as expected. To demonstrate this, I tried the following on Octave
2.1.69 and 2.1.73:
defined the following two functins in respective files:
function y = tttf (a, b)
y = a + b;
function ret = tttf2 (F, x)
ret = feval (F, x);
octave:1> b = 2
b = 2
octave:2> tttf2 (@ (x) tttf (x, b), 3)
error: `b' undefined near line 2 column 23
error: evaluating argument list element number 2
error: called from `?unknown?'
error: evaluating assignment expression near line 2, column 7
error: called from `tttf2' in file `/home/olaf/devel/octave/m/tttf2.m'
Matlab returns 5 as expected.
Octaves anonymous function seems to take the 'b' 'literally', not its
value. (The same applied to function handles used in the body of an
What is going on? Is this a bug? Is there a higher octave version with
If I want to make a wrapper function which changes an argument
representing a function to be called, anonymous functions are probably
the only clean way to go.
- anonymous functions?,
Olaf Till <=