Questions tagged [mex]

MEX-files (MEX stands for Matlab EXecutable) are dynamically linked subroutines produced from C, C++ or Fortran source code that, when compiled, can be run from within MATLAB® in the same way as MATLAB functions or built-in functions.

In general, MATLAB can be quite efficient in performing a wide variety of numerical tasks. However, from time to time there are certain tasks that require more "low-level" control over the execution. For these kind of tasks MATLAB allows for an easy interface to C/C++/Fortran subroutine pre-compiled and ready to be used as any built-in function.

Here are some useful links for MEX-files:

1483 questions
11
votes
1 answer

Using boost in MATLAB MEX library, different from MATLAB's version

We're creating a number of MATLAB MEX files that use our communications library. This communication library uses Boost a lot. Now, MATLAB also uses boost internally, which means that in a standard setup, we cannot use a boost version different from…
Ives
  • 240
  • 3
  • 9
10
votes
1 answer

Difference between size_t and mwSize when compiling C MEX-files for Matlab

I am currently working on porting some C MEX-files for 32-bit Matlab to 64-bit Matlab. While doing so, I have encountered two types, one coming from the Matlab people, and one which is C standard. This is what the Matlab documentation is saying…
Har
  • 377
  • 2
  • 13
10
votes
2 answers

how to read an integer array in MEX-function

I am passing an integer array of uint8 type from MATLAB to a MEX-function. How do I read these values? I tried using: int *n; n = (int * ) mxGetData(prhs[0]); but the values come out as junk. I also tried double *n; n= mxGetPr(prhs[0]); and in…
Madhu
  • 111
  • 1
  • 1
  • 5
10
votes
3 answers

Setting up mex to use the Visual Studio 2010 compiler

I have Visual Studio 2010 installed. However, MATLAB doesn't find the compiler. >> mex -setup Please choose your compiler for building external interface (MEX) files: Would you like mex to locate installed compilers [y]/n? y Select a compiler:…
Etan
  • 17,014
  • 17
  • 89
  • 148
10
votes
2 answers

shared library locations for matlab mex files:

I am trying to write a matlab mex function which uses libhdf5; My Linux install provides libhdf5-1.8 shared libraries and headers. However, my version of Matlab, r2007b, provides a libhdf5.so from the 1.6 release. (Matlab .mat files bootstrap hdf5,…
shabbychef
  • 1,940
  • 3
  • 16
  • 28
10
votes
2 answers

Matlab Mex library lifecycle

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…
panos
  • 105
  • 7
10
votes
2 answers

matlab in C C++ and C C++ in matlab

It seems that are several ways to call matlab in C C++ and to call C C++ in matlab. While I try to list them here, please point it out If I miss something. To call C C++ in matlab, there are also two methods. The first one is to call functions in C…
Tim
  • 1
  • 141
  • 372
  • 590
10
votes
3 answers

Profiling a mex-function

I have just rewritten a Matlab program in c++ as a mex-function to speed things up, with fantastic results. This optimization decision was a very very good idea, with up to a factor 20 speed up without threading. It still left me curious about what…
AnnaR
  • 3,166
  • 6
  • 35
  • 39
9
votes
1 answer

How to configure CMake to compile MEX-files?

I would like to compile MEX-files (MATLAB executable) in CLion instead of in MATLAB (which gives no help on writing C code). However, MEX-files require the #include mex.h(pp), which is not available on normal C++. Moreover, the format, which does…
veritas9872
  • 101
  • 2
  • 5
9
votes
3 answers

GCC compilation very slow (large file)

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…
user650261
  • 2,115
  • 5
  • 24
  • 47
9
votes
1 answer

Why does std::nth_element return sorted vectors for input vectors with N < 33 elements?

I am using std::nth_element to get a (roughly correct) value for a percentile of a vector, like so: double percentile(std::vector &vectorIn, double percent) { std::nth_element(vectorIn.begin(), vectorIn.begin() +…
stack_horst
  • 302
  • 3
  • 11
9
votes
3 answers

Matlab mex-file with mexCallMATLAB is almost 300 times slower than the corresponding m-file

I started implementing a few m-files in C++ in order to reduce run times. The m-files produce n-dimensional points and evaluate function values at these points. The functions are user-defined and they are passed to m-files and mex-files as function…
Meteor
  • 93
  • 1
  • 5
9
votes
3 answers

Force MATLAB to reload library linked in mex function

I have a Mex-function, say myfunction.mexmaci64 (which is the correct ending on OS X). Now, myfunction is linked against a library mylibrary.dylib. Both, mex-file and library, reside in the same folder. Now, whenever I change something in…
Thilo
  • 8,827
  • 2
  • 35
  • 56
8
votes
1 answer

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

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…
Framester
  • 33,341
  • 51
  • 130
  • 192
8
votes
1 answer

Why is OpenMP in a mex file only producing 1 thread?

I am new to OpenMP. I have the following code which compiles fine using Matlab mex configured with MSVS2010. The computer has 8 processors available (which I checked also by using matlabpool). #include "mex.h" #include typedef unsigned char…
twerdster
  • 4,977
  • 3
  • 40
  • 70
1
2
3
98 99