A.2.7 Вызов других функций в Mex-файлах
Возможен вызов других функций Octave изнутри mex-файла с помощью mexCallMATLAB. Пример использования mexCallMATLAB можно увидеть в примере ниже.
#include "mex.h"
void
mexFunction (int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
char *str;
mexPrintf ("Starting file myfeval.mex\n");
mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs);
if (nrhs < 1 || ! mxIsChar (prhs[0]))
mexErrMsgTxt ("ARG1 must be a function name");
str = mxArrayToString (prhs[0]);
mexPrintf ("I'm going to call the function %s\n", str);
if (nlhs == 0)
nlhs = 1; // Octave's automatic 'ans' variable
/* Cast prhs just to get rid of 'const' qualifier and stop compile warning */
mexCallMATLAB (nlhs, plhs, nrhs-1, (mxArray**)prhs+1, str);
mxFree (str);
} Если этот код находится в файле myfeval.c и компилируется в myfeval.mex, то пример его использования выглядит так
a = myfeval ("sin", 1)
⇒ Starting file myfeval.mex
I have 2 inputs and 1 outputs
I'm going to call the interpreter function sin
a = 0.84147 Обратите внимание, что использовать функции-обработчики или встроенные функции внутри mex-файла нельзя.
© 1996–2022 The Octave Project Developers
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://docs.octave.org/v5.2.0/Calling-Other-Functions-in-Mex_002dFiles.html