Category : matlab

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

There are certainly some differences between a macro and a function But I want to know that is it okay that we say that macros in c/c++ are same as script in MATLAB? The difference between macro and function in c/c++ is same like the difference between script and function in MATLAB? Source: Windows Questions ..

Read more

In a .cpp file i have icluded the following #include "MatlabDataArray.hpp" #include "MatlabEngine.hpp" And I get the following error: fatal error: MatlabDataArray.hpp: No such file or directory the path of the files is /usr/local/MATLAB/R2020b/extern/include/ and I have tried to put it in the c_cpp_properties.json: { "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "../../../../usr/local/MATLAB/R2020b/extern/include", "/usr/local/MATLAB/R2020b/extern/include/**", ..

Read more

Does anybody know why the following vector called random_pG is not filling up from a CSV file? # include <iostream> # include <stdlib.h> # include <string.h> # include <fstream> # include <vector> # include <sstream> // std::stringstream using namespace std; double random_pG[150]; double random_z_prev[150]; double zi_prevCells[150][4]; //Functions prototypes void ReadData1(double random_pG[], string); void ReadData2(double zi_prevCells[][4], ..

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 am using a simple matlab code to send serial data to a COM port device, however I am having issues and would like an equivalent C/C++ code to achieve the same result. Shown below is the MATLAB code. s_port = serialport(‘COM1′,9600); configureTerminator(s_port,’CR’); write(s_port,char([50 01]),"char"); pause(1) write(s_port,char([16 2 150]),"char") write(s_port,char([55 18]),"char") write(s_port,char(54),"char"); I attempted to ..

Read more