[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C++ and octave
From: |
Geraint Paul Bevan |
Subject: |
Re: C++ and octave |
Date: |
Wed, 14 Jan 2004 21:59:45 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031221 Thunderbird/0.4 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Søren Hauberg wrote:
| Hi
| Thanks for the quick reply, and I'm sorry about my late reply
|
| A method that I need to implement on C++ needs to compute the mean and
| standard deviation of the values in a matrix. I cannot find any
| functions I can call from C++ to compute these values and google gives
| me nothing.
|
| Typing "type mean" inside octave gives me an m-file implementation of
| the mean function. Does this mean I can't call mean from C++ ?
| At the moment I have just a quick 'n' dirty implementation of mean & std
| in C++. Is this really the way to go?
|
| Soren
|
You can call any Octave function (.m or .oct) from C++ DLD functions
using "feval". Of course, there will probably be a fairly significant
overhead compared to coding the function directly in C++ as the Octave
interpreter has to be invoked.
The (quick and dirty) code below demonstrates how you can call the
"mean" function from a DLD:
address@hidden:~/mean$ cat my_mean.cc
#include <octave/oct.h>
#include <octave/parse.h>
DEFUN_DLD (my_mean, args, , "mean")
{
~ octave_value_list retval;
~ double mean;
~ mean = feval ("mean", args(0))(0).double_value();
~ retval(0) = mean;
~ return retval;
}
address@hidden:~/mean$ mkoctfile my_mean.cc
address@hidden:~/mean$ echo "mean([1,2,5]) , my_mean([1,2,5])" | octave -q
ans = 2.6667
ans = 2.6667
- --
Geraint Bevan
http://homepage.ntlworld.com/geraint.bevan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iEYEARECAAYFAkAFu9EACgkQcXV3N50QmNM4ggCdHYp/4yHyGnA5tGZyDGss6ptT
SXMAn2UDGwlPzrzVce5Pd0idHHBOizd3
=Dnuh
-----END PGP SIGNATURE-----
-------------------------------------------------------------
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
-------------------------------------------------------------