[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: object behavior with Octave...
From: |
Ben Abbott |
Subject: |
Re: object behavior with Octave... |
Date: |
Sat, 14 Feb 2009 11:34:02 -0500 |
On Feb 14, 2009, at 9:54 AM, James Moliere wrote:
looking at the URL
http://asis.epfl.ch/SCI.MATH/octave-2.0.16/Octave-FAQ_3.html
I don't see the capability below. Can I assign functions to variables
in a structure and call them?
# simple increment example
function [ ret ] = tt (a)
x.a=a
function result = anon(x)
x.a = x.a+1
result = x
endfunction
x.increment = @anon
ret = x
endfunction
... I'd like to do something like this
k = tt(1)
k.increment(k) % or k.increment() without passing in k
... I'd expect an answer of 2.
Your example can be entered at the command line as ...
function result = anon(x)
x.a = x.a+1;
result = x;
endfunction
function [ ret ] = tt (a)
x.a=a;
x.increment = @anon;
ret = x;
endfunction
x.a = 0;
anon(x)
ans =
{
a = 1
}
x = tt(1)
x =
{
a = 1
increment =
anon
}
x.increment(x)
ans =
{
a = 2
increment =
anon
}
If you try x.increment() it will produce an error, because that is the
same as calling anon().
Ben
- Re: development version does not compile, (continued)
- Re: development version does not compile, Bertrand Roessli, 2009/02/13
- Re: development version does not compile, John W. Eaton, 2009/02/13
- Re: development version does not compile, Bertrand Roessli, 2009/02/13
- Re: development version does not compile, John W. Eaton, 2009/02/13
- Re: development version does not compile, Bertrand Roessli, 2009/02/13
- object behavior with Octave..., James Moliere, 2009/02/14
- Re: object behavior with Octave..., Ben Abbott, 2009/02/14
- Re: object behavior with Octave..., James Moliere, 2009/02/14
- Message not available
- Re: object behavior with Octave...,
Ben Abbott <=
- Message not available
- Re: object behavior with Octave..., Ben Abbott, 2009/02/14
- Re: object behavior with Octave..., John W. Eaton, 2009/02/14
- Re: object behavior with Octave..., James Moliere, 2009/02/14
- Re: object behavior with Octave..., Søren Hauberg, 2009/02/14
- Re: object behavior with Octave..., James Moliere, 2009/02/14
- Re: object behavior with Octave..., John W. Eaton, 2009/02/14
- Re: object behavior with Octave..., James Moliere, 2009/02/14
- Re: object behavior with Octave..., Ben Abbott, 2009/02/14
- Re: object behavior with Octave..., John W. Eaton, 2009/02/14
- Re: object behavior with Octave..., Sergei Steshenko, 2009/02/14