[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: inline functions
From: |
Etienne Grossmann |
Subject: |
Re: inline functions |
Date: |
Sat, 10 Aug 2002 18:11:56 +0100 |
User-agent: |
Mutt/1.3.28i |
Hello,
On Sat, Aug 10, 2002 at 01:32:42PM +0000, Steffan Berridge wrote:
#
# Hi,
#
# I have just started using Octave, having used Matlab for a
# while. In Matlab I have often used inline functions, they
# are very convenient for example when passing a function as
# an argument.
#
# For example, the following is a function returning the
# square of the argument:
#
# fun = inline('x^2','x');
I don't know of any inline() function for Octave, but you can define
new functions with eval(). You can then use its name (a string) as a
pointer to the function, and call it with feval(). Example :
## myfun() is defined as a global function
eval ("function y = myfun (x), y = x.^2; end;")
y = feval ("myfun", xx);
# One can then pass this function as an argument to another
# function:
#
# x = foo(fun,...);
#
# So my question is, is there an equivalent construction in
# Octave? If not, what is the best way to pass functions as
# arguments?
Currently, use a string holding the function name.
Hth,
Etienne
--
Etienne Grossmann ------ http://www.isr.ist.utl.pt/~etienne
-------------------------------------------------------------
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
-------------------------------------------------------------