mex

How to pass an integer array from matlab to mex?

倖福魔咒の 提交于 2019-12-06 02:55:12
I want to pass an integer array from matlab to mex. The array is for example a=[1 2 3 4]. I wrote the following code: #include <math.h> #include <stdio.h> #include <stdlib.h> #include <mkl.h> #include "mkl_vml.h" #include "mex.h" #include "matrix.h" #include "mkl_vsl.h" /* main fucntion */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int n, *a; /* make pointers to input data */ n = (int)mxGetScalar(prhs[0]); a = (int *)mxGetData(prhs[1]); mexPrintf("a[0]:%d \t a[1]:%d \t a[2]:%d \n", a[0],a[1],a[2]); } When I run it the result is: a[0]:0 a[1]:1072693248 a[2]:0

How to loop through matrix elements in mex c++ function for MATLAB?

醉酒当歌 提交于 2019-12-06 01:35:49
问题 I am trying to index write an external c++ function for MATLAB using mex to manipulate matrices, and am not able to use multidimensional indexing. There are examples provided here, but I have not found how to fix the problem I describe below. I have a sample matrix: >> mat mat = 1 10 2 20 3 30 4 40 5 50 Currently I use a linear index through the matrix which works: #include <mex.h> #include <iostream> using namespace std; void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray

Periodically send data to MATLAB from mexFile

穿精又带淫゛_ 提交于 2019-12-05 23:40:01
I'm working right now on a Data Acquisition Tool completely written in MATLAB. It was the wish of my colleagues that i write this thing in MATLAB so that they can expand and modify it. The Software needs to grab a picture from two connected USB cameras. The API for these cameras is written in C++ and is documented -> Here . Here is the Problem: When i write a mex file which grabs a picture it includes the initialization and configuration-loading of the cameras which takes a long time. When i want to grab the pictures this way it takes MATLAB over 1 second to perform the task. The cameras are

How to provide Matlab with the old gcc version it wants?

非 Y 不嫁゛ 提交于 2019-12-05 22:10:13
问题 On my computer I have Ubuntu 10.10 with gcc 4.4.4. I try to compile some mex files which use CUDA and I get following error message: >> cns_build('hmax') compiling... /home/leMe/hmax/cns/source/common_dec.h(54): warning: omission of exception specification is incompatible with previous function "operator new(size_t)" /usr/include/c++/4.4/new(91): here /home/leMe/hmax/cns/source/common_dec.h(55): warning: omission of exception specification is incompatible with previous function "operator new[

Memory leak in MATLAB > MEX file > managed DLL

眉间皱痕 提交于 2019-12-05 22:04:01
My MEX file is written in C++/CLI and calls a DLL written in C#. When gcnew'ing an object, shouldn't it be garbage collected when the mexFunction returns? Its references should be lost but nothing seems to be garbage collected... each call to the mex function increases MATLAB 's memory allocation (and no, the memory is not used for MATLAB variables). I've experimented with creating a large dummy value with narrow scope and when stepping through the MEX file I can see the memory allocated and released. But not so with the main object created in the mexFunction =( I've tried to delete it in the

GCC compilation very slow (large file)

我的未来我决定 提交于 2019-12-05 19:41:10
问题 I am trying to compile a large C file (specifically for MATLAB mexing). The C file is around 20 MB (available from the GCC bug tracker if you want to play around with it). Here is the command I am running and the output to screen, below. This has been running for hours, and as you can see, optimization is already disabled (-O0). Why is this so slow? Is there a way I can make this faster? (For reference: Ubuntu 12.04 (Precise Pangolin) 64 bit and GCC 4.7.3) /usr/bin/gcc -c -DMX_COMPAT_32 -D

convert from float* to vector<float >

僤鯓⒐⒋嵵緔 提交于 2019-12-05 19:26:45
I have a function float * pointwise_search(vector<float > &P,vector<float > &Q,float* n, int len ) . I want matlab call it so I need to write a mexFunction. void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs != 4) { mexErrMsgTxt("Input is wrong!"); } float *n = (float*) mxGetData(prhs[2]); int len = (int) mxGetScalar(prhs[3]); vector<float > Numbers= (vector<float >)mxGetPr(prhs[0]); vector<float > Q= (vector<float >)mxGetPr(prhs[1]); plhs[1] = pointwise_search(Numbers,Q,n,len ); } But I found that vector<float > Numbers= (vector<float >)mxGetPr(prhs[0]);

Matlab Mex file compile

浪子不回头ぞ 提交于 2019-12-05 18:41:43
I'm trying to compile a mex file to use socket connection within matlab. The problem is that it is always saying that I don't have sdk or compiler installed. But I have installed visual studio 2010 express, visual studio 2012 express, visual studio 2012 professional and nothing is changing the error. Also I have installed the sdk. Is there anything that I could try? The matlab version is R2012b and I'm using windows 7, 64 bits. Thanks! You can try gnumex , which lets you access the mingw compilers on Windows. It works with mingw-w64 which is the 64 bit version of mingw . You have to install

Matlab 2012a Mex to work with Xcode 4.5 on Mountain Lion

给你一囗甜甜゛ 提交于 2019-12-05 17:29:56
I have Mountain Lion installed with Xcode 4.5 and Matlab 2012a. I installed and ran the patch supplied on the MathWorks website however I still received the following error: /Applications/MATLAB_R2012a.app/bin/mex: line 305: llvm-gcc-4.2: command not found /Applications/MATLAB_R2012a.app/bin/mex: line 1326: llvm-gcc-4.2: command not found mex: compile of ' "hello.c"' failed. Error using mex (line 206) Is there a known solution for that ? Solution: Open Xcode --> Preferences --> Downloads --> Install "Command Line Tools" The MathWorks patch is still needed. Resolved issue for me. You don't need

Matlab limits TBB but not OpenMP

拜拜、爱过 提交于 2019-12-05 16:42:10
I'm only asking this to try to understand what I've spent 24 hours trying to fix. My system: Ubuntu 12.04.2, Matlab R2011a, both of them 64-bit, Intel Xeon processor based on Nehalem. The problem is simply, Matlab allows OpenMP based programs to utilize all CPU cores with hyper-threading enabled but does not allow the same for TBB. When running TBB, I can launch only 4 threads, even when I change the maxNumCompThreads to 8. While with OpenMP I can use all the threads I want. Without Hyper-threading, both TBB and OpenMP utilize all 4 cores of course. I understand Hyper-threading and that its