This is a small example of a library that can be called from MATLAB (C) to execute a simple matrix-multipl. using the BIAS-libraries. It takes two matrices as arguments and returns the result of the multiplication.When this library has been compiled, copy it to your MATLAB-workspace and rename it to: SomeFuncName.mexglx (Linux) or SomeFuncName.dll (WIN32). Afterwards you can call the mex-file from within MATLAB using: C = SomeFuncName(A,B) (A,B initialized with matrices, C is used to store the result)
- Author
- apetersen
- Date
- 07/04/2008
#include <Base/Math/MatLabInterface.hh>
using namespace BIAS;
void mexFunction(
int nlhs,
mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
{
if (nrhs != 2 || nlhs != 1)
MATLABERR("Invalid argument count!");
MATLABERR("First argument (source) is invalid!");
return;
}
MATLABERR("Second argument (kernel) is invalid!");
return;
}
MATLABERR("Error: invalid matrix dimensions!");
return;
}
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
mexPrintf("mat1[%d][%d]: %f ; ", i, j, mat1[i][j]);
}
mexPrintf("\n");
}
result = mat1 * mat2;
MATLABERR("Error converting result to MATLAB-datatypes!");
return;
}
return;
}