Skip to content

Instantly share code, notes, and snippets.

@yansyaf
Last active December 17, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yansyaf/5624447 to your computer and use it in GitHub Desktop.
Save yansyaf/5624447 to your computer and use it in GitHub Desktop.
#include "mex.h"
/* Input Arguments */
#define X1 prhs[0]
#define X2 prhs[1]
/* Output Arguments */
#define Y plhs[0]
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
printf("adder\n");
/* Check for proper number of arguments */
if (nrhs != 2) {
mexErrMsgTxt("Two input arguments required.");
} else if (nlhs > 1) {
mexErrMsgTxt("Too many output arguments.");
} else {
printf("Adder from MEX function\n");
}
//Allocate ouptut
Y = mxCreateNumericMatrix(1, 1, mxDOUBLE_CLASS, mxREAL);
//Adder function
*mxGetPr(Y) = *mxGetPr(X1) + *mxGetPr(X2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment