Category : mex

This question shows how to return a double matrix to matlab using a map object. Pass C++ Eigen matrix to Matlab mex output The following works for non-complex data. double *outputPtr; plhs[0] = mxCreateDoubleMatrix((mwSize)n, (mwSize)m, mxREAL); outputPtr = mxGetPr(plhs[0]); Map<MatrixXd> output(outputPtr, n, m); Since matlab stores real and complex elements of a matrix separately rather ..

Read more

I have a problem with MEX files in C/C++ coding. I need to return a double complex array to Matlab but I am not able to do that and I don’t find information about it. I show my code with some tries: double complex output[nSymb]; nlhs = 1; plhs[0] = mxCreateDoubleMatrix(nSymb,(mwSize)nlhs,mxCOMPLEX); plhs[0] = output; memcpy(plhs, ..

Read more

I have compiled mex file from C++ code: #include "mex.h" #include "matrix.h" #include "fdtd-macro.h" #include "copyMatrix.cpp" #include "global_var.h" int nx,ny,nz,linearSizeEx,linearSizeEy,linearSizeEz; int ExM,ExN,ExP,EyM,EyN,EyP,EzM,EzN,EzP,HxM,HxN,HxP,HyM,HyN,HyP,HzM,HzN,HzP; double *Ex,*Ey,*Ez,*tmpEx,*tmpEy,*tmpEz; const mwSize *dimEx,*dimEy,*dimEz; const mwSize *dimCexe,*dimCexhy,*dimCexhz,*dimCeye,*dimCeyhx,*dimCeyhz,*dimCeze,*dimCezhx,*dimCezhy; using namespace std; void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) { //read input from MATLAB calling Ex = mxGetPr(prhs[0]); Ey = mxGetPr(prhs[1]); Ez ..

Read more

I have seen a lot information about how to use MATLAB coder to convert MATLAB codes to C++ code. Unfortunately, I do not have a license for coder. However, I recall back in my graduate studies in 2002-2003, I could use "mex" command with some specific options to convert MATLAB code to C and then ..

Read more

I am writing a program to solve a computationally heavy optimization problem. To improve speed I am using mex-files for certain parts of the code. I know I can in theory call Matlab functions from a mex-file (link 1). However, is this recommended? What does it typically do for speed? Alternatively, I could only use ..

Read more