Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 3e60ff9d4d6f58c8fbd17208f14089fa > files > 83

octave-doc-3.2.3-3mdv2010.0.i586.rpm

<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.13">
<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">
<a name="Calling-Other-Functions-in-Mex-Files"></a>
<a name="Calling-Other-Functions-in-Mex_002dFiles"></a>
<p>
Previous:&nbsp;<a rel="previous" accesskey="p" href="Sparse-Matrices-with-Mex_002dFiles.html#Sparse-Matrices-with-Mex_002dFiles">Sparse Matrices with Mex-Files</a>,
Up:&nbsp;<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 &lt; 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)
     &rArr; 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>