Unrecognized function or variable 'mexUnwrap'.

조회 수: 3 (최근 30일)
Pierre
Pierre 2024년 7월 26일
댓글: Walter Roberson 2024년 7월 29일
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
Steven Lord
Steven Lord 2024년 7월 29일
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 2024년 7월 29일
Perhaps @Pierre is using Apple Silicon and so needs to mex the code in order to generate a mexmaca64 file...

댓글을 달려면 로그인하십시오.

답변 (1개)

Harsh
Harsh 2024년 7월 29일
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!

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by