1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
<html lang="en">
<head>
<title>Calling Other Functions in Mex-Files - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Mex_002dFiles.html#Mex_002dFiles" title="Mex-Files">
<link rel="prev" href="Sparse-Matrices-with-Mex_002dFiles.html#Sparse-Matrices-with-Mex_002dFiles" title="Sparse Matrices with Mex-Files">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Calling-Other-Functions-in-Mex-Files"></a>
<a name="Calling-Other-Functions-in-Mex_002dFiles"></a>
Previous: <a rel="previous" accesskey="p" href="Sparse-Matrices-with-Mex_002dFiles.html#Sparse-Matrices-with-Mex_002dFiles">Sparse Matrices with Mex-Files</a>,
Up: <a rel="up" accesskey="u" href="Mex_002dFiles.html#Mex_002dFiles">Mex-Files</a>
<hr>
</div>
<h4 class="subsection">A.2.7 Calling Other Functions in Mex-Files</h4>
<p>It is also possible call other Octave functions from within a mex-file
using <code>mexCallMATLAB</code>. An example of the use of
<code>mexCallMATLAB</code> can be see in the example below
<pre class="example"><pre class="verbatim"> #include "mex.h"
void
mexFunction (int nlhs, mxArray* plhs[], int nrhs,
const mxArray* prhs[])
{
char *str;
mexPrintf ("Hello, World!\n");
mexPrintf ("I have %d inputs and %d outputs\n", nrhs,
nlhs);
if (nrhs < 1 || ! mxIsString (prhs[0]))
mexErrMsgTxt ("function name expected");
str = mxArrayToString (prhs[0]);
mexPrintf ("I'm going to call the function %s\n", str);
mexCallMATLAB (nlhs, plhs, nrhs-1, prhs+1, str);
mxFree (str);
}
</pre></pre>
<p>If this code is in the file <samp><span class="file">myfeval.c</span></samp>, and is compiled to
<samp><span class="file">myfeval.mex</span></samp>, then an example of its use is
<pre class="example"> myfeval("sin", 1)
a = myfeval("sin", 1)
Hello, World!
I have 2 inputs and 1 outputs
I'm going to call the interpreter function sin
a = 0.84147
</pre>
<p>Note that it is not possible to use function handles or inline functions
within a mex-file.
<!-- @node Application Programming Interface for Mex-Files -->
<!-- @subsection Application Programming Interface for Mex-Files -->
<!-- WRITE ME, refer to mex.h and mexproto.h -->
</body></html>
|