mex


mex lets you run C code from matlab.


Example code: test.c and test2.c
The point of this code is to read in a matlab matrix, print some stuff to screen, then return the same matrix with one subtracted from every element.
To compile:
# compile sub-routines separately to avoid annoying mex rules
gcc -FPIC -c test2.c -o test2.o

# make a library of sub-routines
ar rcs libeht.a test2.o

# mexify
mex test.c ./libeht.a
mex test.c ./libeht.a 
To run from matlab:
M = [8 2 ; 3 4 ; 5 6];
tmp = test(M, size(M))


Back to Resources