From help-octave-request at bevo dot che dot wisc dot edu Wed Jan 14 15:53:05 2004 Subject: Re: C++ and octave From: Geraint Paul Bevan To: =?ISO-8859-1?Q?S=F8ren_Hauberg?= CC: help-octave at bevo dot che dot wisc dot edu Date: Wed, 14 Jan 2004 21:59:45 +0000 -----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: geraint at pavilion:~/mean$ cat my_mean.cc #include #include 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; } geraint at pavilion:~/mean$ mkoctfile my_mean.cc geraint at pavilion:~/mean$| echo "mean([1,2,5]) , my_mean([1,2,5])" 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 -------------------------------------------------------------