[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
function handles & closures - porting from matlab
From: |
John W. Eaton |
Subject: |
function handles & closures - porting from matlab |
Date: |
Wed, 29 Jul 2009 13:03:50 -0400 |
On 29-Jul-2009, Ian Rickard wrote:
| I'm currently trying to port a code base from matlab to octave. It
| uses the following pattern extensively:
|
| function fns = gen_poly_funs(n)
| fns = arrayfun(@(n)(@(x)x.^n),0:n,'UniformOutput',false);
| end
|
| As far as I can tell this pattern breaks in Octave, as there appears
| to be a single global value for n. Is there an easy way to mimic
| matlab's behavior where the n is unique for each of the returned
| function handles?
What version of Octave are you using?
What result are you expecting?
Here is what I see when using Octave 3.2.0:
octave3.2:1> function fns = gen_poly_funs(n)
> fns = arrayfun(@(n)(@(x)x.^n),0:n,'UniformOutput',false);
> end
octave3.2:2> gen_poly_funs (2)
ans =
{
[1,1] =
@(x) x .^ n
[1,2] =
@(x) x .^ n
[1,3] =
@(x) x .^ n
}
Is that not correct?
In any case, if you think you've found a bug in Octave, then please
send a complete bug report to the address@hidden list. To find out
what information to include in your bug report so that it is useful,
please read http://www.octave.org/bugs.html.
jwe