Cpp to Mex conversion

조회 수: 25 (최근 30일)
Stelios Fanourakis
Stelios Fanourakis 2019년 6월 17일
How can I do a cpp conversion to mex?
Thanks
  댓글 수: 1
James Tursa
James Tursa 2019년 6월 17일
Please post more details. Have you looked at the examples in the doc?

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

채택된 답변

James Tursa
James Tursa 2019년 6월 18일
Looks like you have a mismatch with variable types, probably an older piece of code that you are trying to compile on a newer MATLAB version. E.g., the code probably has this definition:
const int *DimsBness;
when it should be this:
const mwSize *DimsBness;
And you probably have something like this:
const int *dims;
or this
int dims[] = {2,3}; /* or whatever */
when it should be this:
const mwSize *dims;
or this
mwSize dims[] = {2,3}; /* or whatever */
Simply update the code with the required types to fix these errors.
  댓글 수: 3
James Tursa
James Tursa 2019년 6월 19일
편집: James Tursa 2019년 6월 19일
Please show the command you are using to compile the mex routine. And then show how you are trying to call the mex routine. Mex routines can be called just like any other regular function by using the function name and an argument list.
Stelios Fanourakis
Stelios Fanourakis 2019년 6월 20일
James
I used this command to create the .mexmaci64
mex -compatibleArrayDims BoneSegmentationDP.cpp
I tried to call it but I get the error of "Not correct or not enough input arguments".
I cannot open to edit this .mexmaci64. I cannot find any other function in the files to call it so to know how many inputs and what inputs it requires.
I also attach both cpp and .mexmaci64 so you tell me what am I doing wrong. Can you open .mexmaci64? Can you tell me its inputs?

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

추가 답변 (1개)

Suryaansh Mata
Suryaansh Mata 2019년 6월 18일
You can use the inbuilt MEX functionality to make use of the source code in C/C++ in MATLAB. Follow the step-by-step detailed instructions given at https://www.mathworks.com/help/matlab/matlab_external/standalone-example.html for the same.
  댓글 수: 2
Stelios Fanourakis
Stelios Fanourakis 2019년 6월 18일
I use the line
mex SegmentBone.cpp
This should do the compiling from cpp to Mex. However, I get the error
mex SegmentBoneDP.cpp
Building with 'Xcode Clang++'.
Error using mex
/Users/steliosphanourakes/Desktop/Matlab/DesMoines/karadokei -
Copy/FANOURAKIS_STELIOS12/20190516144930/SegmentBoneDP.cpp:17:17: error: assigning to 'const int *' from
incompatible type 'const mwSize *' (aka 'const unsigned long *')
DimsBness = mxGetDimensions(prhs[0]);
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018b.app/extern/include/matrix.h:243:25: note: expanded from macro 'mxGetDimensions'
#define mxGetDimensions mxGetDimensions_730
^
/Users/steliosphanourakes/Desktop/Matlab/DesMoines/karadokei -
Copy/FANOURAKIS_STELIOS12/20190516144930/SegmentBoneDP.cpp:30:15: error: no matching function for call to
'mxCreateNumericArray_730'
plhs[0] = mxCreateNumericArray(2,DimsBness,mxDOUBLE_CLASS,mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018b.app/extern/include/matrix.h:275:30: note: expanded from macro 'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018b.app/extern/include/matrix.h:1247:1: note: candidate function not viable: no known
conversion from 'const int *' to 'const mwSize *' (aka 'const unsigned long *') for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018b.app/extern/include/matrix.h:275:30: note: expanded from macro 'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
2 errors generated.
Anyone who can responsibly help me?
Thanks
Maria Cristina Bustos Rodriguez
Maria Cristina Bustos Rodriguez 2020년 1월 31일
I solved that mxCreateNumericArray_730 error by putting this warning:
"mex -DMX_COMPAT_32 yourcode.cpp "

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by