Borrar filtros
Borrar filtros

Unrecognized function or variable 'mexUnwrap'.

6 visualizaciones (últimos 30 días)
Pierre
Pierre el 26 de Jul. de 2024
Comentada: Walter Roberson el 29 de Jul. de 2024
I get this error: “Unrecognized function or variable 'mexUnwrap'” when I run my code. However, the folder containing this C++ file (mexUnwrap.c) is in my path. It also contains mexUnwrap.mexa64, mexUnwrap.mexmaci64, mexUnwrap.mexw64. Do you have any suggestions for solving this problem?
  2 comentarios
Steven Lord
Steven Lord el 29 de Jul. de 2024
What does this command show when you run it on your machine? Do you have a file named mexUnwrap with that extension in the folder?
mexext
mexa64
If not, you'd need to build that MEX-file on that platform.
Walter Roberson
Walter Roberson el 29 de Jul. de 2024
Perhaps @Pierre is using Apple Silicon and so needs to mex the code in order to generate a mexmaca64 file...

Iniciar sesión para comentar.

Respuestas (1)

Harsh
Harsh el 29 de Jul. de 2024
Hi Pierre,
From what I can gather, you are unable to use the “mexUnwrap” function in MATLAB. To use functions or variables from C/C++ in MATLAB, please follow these steps:
1. Create your C/C++ file in the following format, ensuring you include “mex.h”:
#include "mex.h"
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]) {
/* variable declarations */
double num1, num2, result;
/* check for proper number of arguments */
if(nrhs != 2) {
mexErrMsgIdAndTxt("MATLAB:sampleFunction:invalidNumInputs",
"Two inputs required.");
}
if(nlhs != 1) {
mexErrMsgIdAndTxt("MATLAB:sampleFunction:invalidNumOutputs",
"One output required.");
}
/* ensure the inputs are scalar */
if(!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
!mxIsDouble(prhs[1]) || mxIsComplex(prhs[1]) ||
mxGetNumberOfElements(prhs[0]) != 1 ||
mxGetNumberOfElements(prhs[1]) != 1) {
mexErrMsgIdAndTxt("MATLAB:sampleFunction:inputNotScalar",
"Both inputs must be scalar.");
}
/* get the value of the scalar inputs */
num1 = mxGetScalar(prhs[0]);
num2 = mxGetScalar(prhs[1]);
/* perform the addition */
result = num1 + num2;
/* set the output pointer to the output matrix */
plhs[0] = mxCreateDoubleScalar(result);
}
2. Compile the "mex" function using the following command:
mex sampleFunction.c
Once compiled, you can start calling “sampleFunction” in MATLAB.
I hope this helps, thanks!

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by