Skip to content

Instantly share code, notes, and snippets.

@yansyaf
Created May 22, 2013 01:03
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/5624514 to your computer and use it in GitHub Desktop.
Save yansyaf/5624514 to your computer and use it in GitHub Desktop.
#include "mex.h"
#include <string.h>
void mexAdder( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] );
void mexMult( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] );
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
char *functionName;
int functionNameLen;
/* Get the length of the function name string. */
functionNameLen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
/* Allocate memory for input strings. */
functionName = (char *) mxCalloc(functionNameLen, sizeof(char));
/* Copy the string to functionName. */
functionName = mxArrayToString(prhs[0]);
if ( !strcmp(functionName,"adder") ) {
mexAdder(nlhs, plhs, nrhs-1, &(prhs[1]));
} else if ( !strcmp(functionName,"mult") ) {
mexMult(nlhs, plhs, nrhs-1, &(prhs[1]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment