[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Functions as variables
From: |
John W. Eaton |
Subject: |
Re: Functions as variables |
Date: |
Thu, 16 Oct 2003 08:44:56 -0500 |
On 16-Oct-2003, Christoph Dalitz <address@hidden> wrote:
| On Thu, 16 Oct 2003 11:08:41 +0100
| Geraint Paul Bevan <address@hidden> wrote:
| >
| > | how can I pass a function as a variable input argument to another
| > function?
| > | I have tried the following, but it does not work:
| >
| > you have to pass the function as a string and then use the function
| > 'eval' to evaluate it. The following code works:
| >
| Thanks!
|
| While looking up the documentation of eval() I have also found the function
| feval(), which serves my needs even better.
You might also want to use function handles instead of strings. At
least in recent 2.1.x snapshots, you can write
function_handle = @f;
...
feval (function_handle, args);
Function handles have the advantage of preserving enough context to
work for subfunctions (if you use them).
| This reminds me of something different: can it be that octave lacks a
| string concatenation operator? "+" would be the natural candidate, but
| does not work.
|
| I can live with strcat() of course, but just writing a+b would be more
| convenient.
In Matlab, 'abc' + 'def' produces the vector [197, 199, 201].
But you can use ['abc', 'def'] if you prefer.
jwe
-------------------------------------------------------------
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
-------------------------------------------------------------