#include "mex.h"
void myfunction(int a, int b, int* result) {
*result = a + b;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
int a, b, result;
// Check the number of input arguments
if (nrhs != 2) {
mexErrMsgIdAndTxt("myfunction:nrhs", "Two input arguments required.");
}
// Check the number of output arguments
if (nlhs > 1) {
mexErrMsgIdAndTxt("myfunction:nlhs", "Too many output arguments.");
}
// Get the input arguments
a = (int) mxGetScalar(prhs[0]);
b = (int) mxGetScalar(prhs[1]);
// Call the C function
myfunction(a, b, &result);
// Create the output argument
plhs[0] = mxCreateDoubleScalar((double) result);
}