#include #include #include "mex.h" /* to compile this file for use in matlab, type mex mex_speedTest.c mex is the c compiler used by matlab it typically calls gcc, after including the appropriate libraries. If you are using athena, don't forget to "add matlab" first */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double x; unsigned seed; mxArray *mxA; double *prIn; double *prOut; int its; prIn = mxGetPr(prhs[0]); its = (int) prIn[0]; double sum; sum = 0; int i; for (i = 0; i < its; i++){ sum += rand()/(RAND_MAX+1.0); } plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); prOut = mxGetPr(plhs[0]); prOut[0] = sum; }