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 ..
Category : mex
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, ..
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 ..
I have a c++ code that uses opencv2 library and it includes the mexFunction, I would like to compile the code using matlab for windows 10 how to install opencv and make the correct link between mex and opencv to run it from matlab? Source: Windows Que..
I am trying to run C++ code that uses the OpenCV library with MATLAB and mex command (the code already has a mexFunction). I already have the OpenCV library installed, I used it with Python before. I assume that it should work for running C++ code. I am running this command to compile the code ..
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 ..
I’m creating a MEX to find a path between two nodes using the A* algorithm. The code works as expected, retrieves the right result and everything seems to be fine, but when I return from the method that calls the MEX, Matlab simply shuts itself down. As I know sometimes Matlab creates a pointer to ..
I have only been working with mex functions for a couple of weeks, and am now working on writing a Runge-Kutta, 4th order solver as a C++ mex function. I am wondering whether it is possible to take a function as an input. Effectively, it would be nice to have my dynamics function written in ..
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 ..
The title summarizes the goal that is more exactly to dynamically retrieve the number of dimensions of MATLAB arrays passed to armadillo matrices. I would like to change the second and third arguments of mY() and mD() to parametric ones below. // mat(ptr_aux_mem, n_rows, n_cols, copy_aux_mem = true, strict = false) arma::mat mY(&dY[0], 2, 168, ..
Recent Comments