I met errors when compile the test.cpp file.
When i remove #define, and use prhs[] and plhs[] directily, no errors. Many thanks.
My enviroments:
* >> myCompiler = mex.getCompilerConfigurations* * myCompiler = * * CompilerConfiguration with properties:* * Name: 'Microsoft Visual C++ 2012'* Manufacturer: 'Microsoft'* Language: 'C++'* Version: '11.0'* Location: 'C:\Program Files (x86)\Microsoft Visual Studio 11.0'* Details: [1x1 mex.CompilerConfigurationDetails]* LinkerName: ''* LinkerVersion: ''
ERRORS:
# # >> mex test.cpp# # test.cpp # # test.cpp(24) : error C2143: syntax error : missing ')' before ';' # # test.cpp(24) : error C2059: syntax error : ')' # # test.cpp(24) : warning C4390: ';' : empty controlled statement found; is this the intent? # # test.cpp(24) : error C2143: syntax error : missing ';' before '&&' # # test.cpp(24) : error C2143: syntax error : missing ';' before ')' # # test.cpp(30) : error C2143: syntax error : missing ')' before ';' # # test.cpp(30) : error C2059: syntax error : ')' # # test.cpp(30) : warning C4390: ';' : empty controlled statement found; is this the intent? # # test.cpp(30) : error C2143: syntax error : missing ';' before '&&' # # test.cpp(30) : error C2143: syntax error : missing ';' before ')' # # test.cpp(32) : error C2181: illegal else without matching if # # test.cpp(33) : error C2143: syntax error : missing ')' before ';' # # test.cpp(33) : error C2059: syntax error : ')' # # test.cpp(34) : error C2143: syntax error : missing ')' before ';' # # test.cpp(34) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data # # test.cpp(34) : error C2059: syntax error : ')' # # test.cpp(35) : error C2143: syntax error : missing ')' before ';' # # test.cpp(35) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data # # test.cpp(35) : error C2059: syntax error : ')' # # test.cpp(36) : error C2143: syntax error : missing ')' before ';' # # test.cpp(36) : error C2059: syntax error : ')' # # test.cpp(38) : error C2143: syntax error : missing ';' before '=' # # test.cpp(39) : error C2143: syntax error : missing ')' before ';' # # test.cpp(39) : error C2059: syntax error : ')' # # # # C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Compile of 'test.cpp' failed. # # # # Error using mex (line 206)# # Unable to complete successfully.
The following is my code:
# //test.cpp file# #include <math.h># #include "mex.h"# # # #define IS_REAL_2D_FULL_DOUBLE(P) (!mxIsComplex(P) && mxGetNumberOfDimensions(P) ==2 && !mxIsSparse(P) && mxIsDouble(P));# #define IS_REAL_SCALAR(P) (IS_REAL_2D_FULL_DOUBLE(P) && mxGetNumberOfElements(P) ==1);# # # void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])# {# #define B_OUT plhs[0];# #define A_IN prhs[0];# #define P_IN prhs[1];# # double *B, *A, p, colnorm;# int M, N, m, n;# # if(nrhs <1 || nrhs >2)# mexErrMsgTxt("Wrong number of input arguments!\n");# else if (nlhs>1)# mexErrMsgTxt("Too many output arguments! \n");# # if(!IS_REAL_2D_FULL_DOUBLE(A_IN))# mexErrMsgTxt("A must be a real 2D full double array!\n");# # if(nrhs ==1)# p=2.0;# else# if(!IS_REAL_SCALAR(P_IN))# mexErrMsgTxt("P must be a real double scalar. \n");# else # p=mxGetScalar(P_IN);# M = mxGetM(A_IN);# N = mxGetN(A_IN);# A = mxGetPr(A_IN);# # B_OUT = mxCreateDoubleMatrix(M,N,mxREAL);# B = mxGetPr(B_OUT);# # for(n=0; n<N; n++)# {# for(m=0, colnorm = 0.0; m<M; m++) colnorm +=pow(A[m+M*n],p);# colnorm = pow(fabs(colnorm),1.0/p);# # for(m=0; m<M; m++) B[m +M*n] = A[m+M*n]/colnorm;# }# return;# };
Best Answer