2017-01-01 1 views
0

I는 MEX 기능을하고 난 다음 명령 (인터페이스) 매트랩를 사용하고 :왜 mexx 코드에서 arraysize가 0으로 식별됩니까?

Matsize = 30,555

Fv_calc(:,2) = mx_solve_quadratic(QuadraticCoefficients,MatSize); 

게이트웨이 기능은 다음과 같다 :

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 
{ 
    int *arraysizePtr = NULL; 
    arraysizePtr = (int *)mxGetPr(prhs[1]); 
    int arraysize = *arraysizePtr; 
    float *inMatrix = NULL; 
    inMatrix = (float *)mxGetPr(prhs[0]); 
    const float a = 1; /* coefficient for x^2 is always 1*/ 
    plhs[0] = mxCreateNumericMatrix(arraysize, 1, mxSINGLE_CLASS, mxREAL); 
    float *out = (float *)mxGetPr(plhs[0]); 
    float x0; /* the smaller root */ 
    float x1; /* the bigger root */ 
    int fOutput = 0; 
    int i = 0; 
    for (i = 0; i < arraysize; i++) 
    { 
     fOutput = gsl_poly_solve_quadratic(a, inMatrix[i], inMatrix[i + arraysize], &x0, &x1); 
     out[i] = (x1 > 0 ? x1 : 0); 
    } 
} 

전에 코드를 실행했기 때문에 모든 것이 사실입니다. 이제 방금 약간의 변경을했습니다. mex 코드를 실행할 때 arraysize가 0으로 식별되는 이유를 정말로 이해하지 못합니까?

답변

1

mxGetPr 나는 온라인으로 찾을 수있는 것에서 double *을 반환하는 것으로 보입니다. int *arraysizePtr

(https://nl.mathworks.com/help/matlab/apiref/mxgetpr.html?s_tid=gn_loc_drop)

주조를 할당 넌센스을 수득 트로프 *arraysizePtr 액세스시 doubleint 데이터로 해석되도록한다.

+0

코드는 다음과 같이 작성되어야합니다.'double * arraysizePtr = NULL; \t arraysizePtr = mxGetPr (prhs [1]); \t const int arraysize = (int) * arraysizePtr;' – sepideh

관련 문제