#include "mex.h" void test2(); void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* usage: test(M size(M,1), size(M,2)) where M is some matrix */ /* note: plhs = left-hand side and prhs = right-hand side */ /* initilize variables */ mxArray *X; /* output array object */ double *d; /* values of output array */ double *data; /* values of input array */ int m,n; /* input matrix is m x n */ double *t; /* size of M variable */ /* write message to screen */ mexPrintf("This is a test message.\n"); /* determine matrix dimensions */ t = mxGetPr(prhs[1]); mexPrintf("The matrix has dimensionality %i x %i\n", (int)t[0], (int)t[1]); m = (int)t[0]; n = (int)t[1]; /* retrieve the input data */ data = mxGetPr(prhs[0]); /* call pre-compiled code that does nothing */ test2(); /* prepare output matrix and data */ X = plhs[0] = mxCreateDoubleMatrix(m, n, mxREAL); d = mxGetPr(X); /* To access the arrays, use linear indexing. */ /* You can't use [x][y], you have to use [y+x*dimy]. */ /* Here is an example, which we will over-write below. */ d[0] = 17; d[2] = 18; d[1] = 19; d[3] = 20; /* print an element of the array */ mexPrintf("data0 = %g\n", data[0]); mexPrintf("data1 = %g\n", data[1]); mexPrintf("data2 = %g\n", data[2]); mexPrintf("data3 = %g\n", data[3]); /* fill output matrix with input matrix minus one */ int i,j; for (i=0; i