Print arguments in Mex function

#include “mex.h”

void
mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
int i;
char *str[500];

for (i=0; i
/* Check input to be sure it is of type char. */
if(!mxIsChar(prhs[i])){
mexErrMsgTxt(“Input must be of type char.”);
}
/* Copy the string data from prhs and place it into str. */
str[i] = mxArrayToString(prhs[i]);
}

/* Examine input (right-hand-side) arguments. */
mexPrintf(“\nThere are %d right-hand-side argument(s).”, nrhs);
for (i=0; i
mexPrintf(“\n\tInput Arg %i is of type:\t%s, %s”,i,mxGetClassName(prhs[i]),str[i]);
}

/* Examine output (left-hand-side) arguments. */
mexPrintf(“\n\nThere are %d left-hand-side argument(s).\n”, nlhs);
if (nlhs > nrhs)
mexErrMsgTxt(“Cannot specify more outputs than inputs.\n”);
for (i=0; i<nlhs; i++) {
plhs[i]=mxCreateDoubleMatrix(1,1,mxREAL);
*mxGetPr(plhs[i])=(double)mxGetNumberOfElements(prhs[i]);
}
}

This function print out the arguments of mex function.

>> mex mexTest.c
>> mexTest(‘-q’,'f’,'m’,'c’)

There are 4 right-hand-side argument(s).
Input Arg 0 is of type: char, -q
Input Arg 1 is of type: char, f
Input Arg 2 is of type: char, m
Input Arg 3 is of type: char, c

There are 0 left-hand-side argument(s).

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.