There are a couple of issues with the code:
- The way you assign values to the mxArray's
a
andb
is incorrect. - the way you pass the inputs to
mexCallMATLAB
is also not correct
Here is my implementation:
callAdd.c
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *in[2], *out[1];
in[0] = mxCreateDoubleScalar(5);
in[1] = mxCreateDoubleScalar(4);
mexCallMATLAB(1, out, 2, in, "addition");
mexCallMATLAB(0, NULL, 1, out, "disp");
mxDestroyArray(in[0]);
mxDestroyArray(in[1]);
mxDestroyArray(out[0]);
}
This is basically equivalent to calling disp(addition(5,4))
in MATLAB