void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs == 5 && nlhs == 1) { // create object Map<VectorXd> breaks(mxGetPr(prhs[0]), mxGetNumberOfElements(prhs[0])); Map<MatrixXd> K(mxGetPr(prhs[1]), mxGetM(prhs[1]), mxGetN(prhs[1])); Map<MatrixXd> A(mxGetPr(prhs[2]), mxGetM(prhs[2]), mxGetN(prhs[2])); Map<MatrixXd> alpha(mxGetPr(prhs[3]), mxGetM(prhs[3]), mxGetN(prhs[3])); Map<MatrixXd> gamma(mxGetPr(prhs[4]), mxGetM(prhs[4]), mxGetN(prhs[4])); Eval *eval = new Eval(breaks, K, A, alpha, gamma); mxClassID cid; if (sizeof(eval)==4) cid = mxUINT32_CLASS; else if (sizeof(eval)==8) cid = mxUINT64_CLASS; else mexErrMsgIdAndTxt("Drake:ExpPlusPPTmex:PointerSize","Are you on a 32-bit machine or 64-bit machine??"); plhs[0] = mxCreateNumericMatrix(1,1,cid,mxREAL); memcpy(mxGetData(plhs[0]),&eval,sizeof(eval)); // mexPrintf("constructor\n"); mexCallMATLAB(0,NULL,0,NULL,"drawnow"); } else { // retrieve object Eval *eval = NULL; if (nrhs==0 || !mxIsNumeric(prhs[0]) || mxGetNumberOfElements(prhs[0])!=1) mexErrMsgIdAndTxt("Drake:ExpPlusPPTmex:BadInputs","the first argument should be the mex_ptr"); memcpy(&eval,mxGetData(prhs[0]),sizeof(eval)); if (nrhs == 1) { // mexPrintf("delete\n"); mexCallMATLAB(0,NULL,0,NULL,"drawnow"); // delete object if (eval) delete eval; } else { // mexPrintf("eval\n"); mexCallMATLAB(0,NULL,0,NULL,"drawnow"); // eval() function call if (nrhs != 2 || nlhs != 2) { mexErrMsgIdAndTxt("Drake:ExpPlusPPTmex:WrongNumberOfInputs","Usage obj = ExpPlusPPTmex(breaks,K,A,alpha,gamma) or [y,jj] = ExpPlusPPTmex(obj,t)"); } Map<VectorXd> t(mxGetPr(prhs[1]), mxGetNumberOfElements(prhs[1])); int m = static_cast<int>(t.rows()); int d = eval->dim(); plhs[0] = mxCreateDoubleMatrix(d,m,mxREAL); Map<MatrixXd> y(mxGetPr(plhs[0]),d,m); plhs[1] = mxCreateDoubleMatrix(m,1,mxREAL); Map<MatrixXd> jj(mxGetPr(plhs[1]),m,1); eval->compute(t, y, jj); } } }