mex

Is it possible return cell array that contains one instance in several cells?

早过忘川 提交于 2019-11-29 07:23:40
I write some mex function and have to return huge array of strings. I do this as following: mxArray * array = mxCreateCellMatrix(ARRAY_LEN, 1); for (size_t k = 0; k < ARRAY_LEN; ++ k) { mxArray *str = mxCreateString("Hello"); mxSetCell(array, k, str); } prhs[0] = array; However, since the string has always same value, I would like to create only one instance of it. like mxArray * array = mxCreateCellMatrix(ARRAY_LEN, 1); mxArray *str = mxCreateString("Hello"); for (size_t k = 0; k < ARRAY_LEN; ++ k) { mxSetCell(array, k, str); } prhs[0] = array; Does it possible? How the garbage collector

Is it possible to debug mex code with Eclipse?

血红的双手。 提交于 2019-11-29 02:51:26
问题 I am trying to write some mex code but it is painful to debug it on the console with gbd. Is it possible to use Eclipse or the GUI of Matlab? If these are not feasible methods, what is the best way of writing mex code that provides good debug capabilities? 回答1: Debugging C/C++ MEX files in gdb is already comprehensively covered in the official documentation, so my suggestion is to try and integrate gdb with Eclipse CDT. There's plenty of information out there about how to do it properly, so I

Split 3D MatND into vector of 2D Mat opencv

夙愿已清 提交于 2019-11-29 02:26:32
Is it possible to get a 2D Mat object from a 3D data cube stored as MatND in opencv? Basically I'm passing a 3D matrix to a MexFile using "mexopencv". I convert the matrix to a MatND object by using MxArray(prhs[0]).toMatND(). Now I want to split up this datacube along the third dimension into a vector of cv::Mat matrices. I need to make operations on these 2D matrices an therefore iterate over the third dimension. Is there a function to split the data cube as needed? Or maybe a way to get a pointer to the 2D sub matrices of the 3D data cube? Edit: This is my code which uses mexopencv to

Matlab API reading .mat file from c++, using STL container

ぐ巨炮叔叔 提交于 2019-11-29 01:56:51
问题 I have to read some .mat data files from c++, I read through the documentation, but I would like to know how to handle the data in a clean and elegant way, e.g. using std:vector(modest .mat file size(10M~1G), but memory issues should be taken seriously) My function is sth like: #include <stdio.h> #include "mat.h" #include <vector> int matread(const char *file, const vector<double>& pdata_v) { MATFile *pmat; pmat=matOpen("data.mat","r"); if (pmat == NULL) { printf("Error opening file %s\n",

Matlab Mex library lifecycle

情到浓时终转凉″ 提交于 2019-11-28 23:42:07
Does anyone know what the matlab mex library lifecycle is? Specifically I am interested in the following: Is there a way to force the library to be loaded before invoking it? Is the library a singleton or are multiple instances loaded? Are there any hooks for initialization prior to invocation? Is there a destructor hook/signal that can be intercepted when the library is unloaded for cleanup? I did an extensive search here and online and I could not find the answers to these questions. My problem has some performance cost with initialization and I would like to avoid that if possible, without

mex with MATLAB2013a Unrecognized switch: -o

筅森魡賤 提交于 2019-11-28 12:49:36
I am trying to run a code which compiles some c++ codes using mex. I have set up mex with Microsoft Visual C++ 2010. But when I execute the line mex -O fconv.cc -o fconv I get the error compile Usage: MEX [option1 ... optionN] sourcefile1 [... sourcefileN] [objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN] Use the -help option for more information, or consult the MATLAB API Guide. C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Unrecognized switch: -o. I have googled a lot but couldn't find anything of use. It would be great if you someone could help me out here. I have very limited

How to link during Matlab's MEX compilation

瘦欲@ 提交于 2019-11-28 11:21:21
I've written a program of the following form: #include "stuff_I_need.h" int main(){ construct_array(); // uses OpenMP pragma's print_array(); return(0); } that compiles, links, and runs correctly with the following command: `gcc44 -I/home/matteson/sundials/include/ main.c -lm -L/home/matteson/sundials/lib -lsundials_cvode -lsundials_nvecserial -fopenmp -o /home/matteson/MPI_test/CVODE_test/main_test` "gcc44" is simply gcc version 4.4 and is named like this because it's being compiled on a cluster that maintains several versions of gcc. The libraries sundials_cvode and sundials_nvecserial are

Linking and LOADING static .lib with mex

随声附和 提交于 2019-11-28 09:49:21
问题 So, I have a MEX gateway script file that calls my C source code. I've used the -L and -I commands to link my 64-bit compiled GSL libraries (.libs) to my mex executable, which is then compiled under the extension of .mexw64. I want for this executable to be transferred to another windows machine and run fine, without any GSL libraries installed. That is the the only solution, I don't care what he arguments are regarding the benefits of the dynamic linking/code generation upon compile-time are

Working with preallocated arrays in Matlab's mex function

◇◆丶佛笑我妖孽 提交于 2019-11-28 08:56:09
问题 I wrote a simple mex function which updates already allocated by Matlab array: mex_test_array.c #include "mex.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *x = mxGetPr(prhs[0]); x[0] = 3.1416; } Test 1: >> y = zeros(2, 2); >> mex_test_array(y); >> y y = 3.1416 0 0 0 Test 2: >> y = zeros(2, 2); >> mex_test_array(y(:, 1)); >> y y = 0 0 0 0 Why it doesn't work on sub-matrix (Test 2) ? Is it possible to make it work? Please advise. Remark: I understand,

MATLAB Mex Socket Wrapper Library

眉间皱痕 提交于 2019-11-28 05:36:54
问题 Have anybody written a POSIX socket wrapping library for MATLAB using Mex? I basically want to open, write and read. Both sync and asynchronous alternatives would be nice. My main target platform is Linux. I know Mex and I know POSIX sockets. I just want to make certain that nobody else has done this already? 回答1: If you want to work with sockets, you have two options: 1) use Java capabilities from inside MATLAB (see this answer here on SO for a quick example): TCP/IP Socket Communications in