/* * function r=mrank(n) */ static mxArray * Mmrank(int nargout_, mxArray * n) { mexLocalFunctionTable save_local_function_table_ = mclSetCurrentLocalFunctionTable(&_local_function_table_mrank); mxArray * r = NULL; mxArray * ans = NULL; mxArray * k = NULL; mclCopyArray(&n); /* * r=zeros(n,1); */ mlfAssign(&r, mlfZeros(mclVa(n, "n"), _mxarray0_, NULL)); /* * for k=1:n */ { int v_ = mclForIntStart(1); int e_ = mclForIntEnd(mclVa(n, "n")); if (v_ > e_) { mlfAssign(&k, _mxarray1_); } else { /* * r(k)=my_rank(magic(k)); * end */ for (; ; ) { mclIntArrayAssign1( &r, mlfMy_rank(mlfMagic(mlfScalar(v_)), NULL), v_); if (v_ == e_) { break; } ++v_; } mlfAssign(&k, mlfScalar(v_)); } } /* * r */ mclPrintArray(mclVv(r, "r"), "r"); mclValidateOutput(r, 1, nargout_, "r", "mrank"); mxDestroyArray(k); mxDestroyArray(ans); mxDestroyArray(n); mclSetCurrentLocalFunctionTable(save_local_function_table_); return r; }
main(int argc,char **argv) { mxArray *N; mxArray *R; int n; if(argc>=2){ n=atoi(argv[1]); }else { n=12; } PkgInitialize(); N=mlfScalar(n); R=mlfMrank(N); mlfPrintMatrix(R); mxDestroyArray(N); mxDestroyArray(R); PkgTerminate(); }
int main (int argc, char *argv[]) /* Programmer written coded to call mlfMy_function */ { mxArray *my_cpu; int rank; rank=(int)atoi(argv[1]); /* fprintf(stdout, " rank: %d\r\n", rank); */ multpkgInitialize(); my_cpu=mlfScalar(rank); /* Call the mlfMy_function function. */ mlfMy_function(my_cpu); multpkgTerminate(); return(0); }
/* * function theImage=gasket(numPoints) */ static mxArray * Mgasket(int nargout_, mxArray * numPoints) { mexLocalFunctionTable save_local_function_table_ = mclSetCurrentLocalFunctionTable(&_local_function_table_gasket); mxArray * theImage = NULL; mxArray * i = NULL; mxArray * theRand = NULL; mxArray * startPoint = NULL; mxArray * corners = NULL; mclCopyArray(&numPoints); /* * theImage =zeros(1000,1000); */ mlfAssign(&theImage, mlfZeros(_mxarray0_, _mxarray0_, NULL)); /* * corners=[866 1;1 500;866 1000]; */ mlfAssign(&corners, _mxarray1_); /* * startPoint=[866 1]; */ mlfAssign(&startPoint, _mxarray3_); /* * theRand=rand(numPoints,1); */ mlfAssign( &theRand, mlfNRand(1, mclVa(numPoints, "numPoints"), _mxarray5_, NULL)); /* * theRand=ceil(theRand*3); */ mlfAssign( &theRand, mlfCeil(mclMtimes(mclVv(theRand, "theRand"), _mxarray6_))); /* * for i=1:numPoints */ { int v_ = mclForIntStart(1); int e_ = mclForIntEnd(mclVa(numPoints, "numPoints")); if (v_ > e_) { mlfAssign(&i, _mxarray7_); } else { /* * startPoint=floor((corners(theRand(i),:)+startPoint)/2); * theImage(startPoint(1),startPoint(2))=1; * end */ for (; ; ) { mlfAssign( &startPoint, mlfFloor( mclMrdivide( mclPlus( mclArrayRef2( mclVv(corners, "corners"), mclIntArrayRef1(mclVv(theRand, "theRand"), v_), mlfCreateColonIndex()), mclVv(startPoint, "startPoint")), _mxarray8_))); mclArrayAssign2( &theImage, _mxarray5_, mclIntArrayRef1(mclVv(startPoint, "startPoint"), 1), mclIntArrayRef1(mclVv(startPoint, "startPoint"), 2)); if (v_ == e_) { break; } ++v_; } mlfAssign(&i, mlfScalar(v_)); } } mclValidateOutput(theImage, 1, nargout_, "theImage", "gasket"); mxDestroyArray(corners); mxDestroyArray(startPoint); mxDestroyArray(theRand); mxDestroyArray(i); mxDestroyArray(numPoints); mclSetCurrentLocalFunctionTable(save_local_function_table_); return theImage; }
mxArray * MIPEMProcessAuditoryModel_IPEMProcessAuditoryModelSafe(int nargout_, mxArray * inNumOfChannels, mxArray * inFirstFreq, mxArray * inFreqDist, mxArray * inInputFileName, mxArray * inInputFilePath, mxArray * inOutputFileName, mxArray * inOutputFilePath, mxArray * inSampleFrequency, mxArray * inSoundFileFormat) { // Declare C variables for the Matlab arguments and set to defaults long theNumOfChannels = -1; double theFirstFreq = -1.0; double theFreqDist = -1.0; char* theInputFileName = NULL; char* theInputFilePath = NULL; char* theOutputFileName = NULL; char* theOutputFilePath = NULL; double theSampleFrequency = -1.0; long theSoundFileFormat = -1; // Convert Matlab arguments to C arguments // Dimension/type checking should already be done !!! theNumOfChannels = (long)mxGetScalar(inNumOfChannels); theFirstFreq = mxGetScalar(inFirstFreq); theFreqDist = mxGetScalar(inFreqDist); theInputFileName = mxArrayToString(inInputFileName); theInputFilePath = mxArrayToString(inInputFilePath); theOutputFileName = mxArrayToString(inOutputFileName); theOutputFilePath = mxArrayToString(inOutputFilePath); theSampleFrequency = mxGetScalar(inSampleFrequency); theSoundFileFormat = (long)mxGetScalar(inSoundFileFormat); #ifdef _DEBUG // Show the arguments printf("theNumOfChannels = %li\n",theNumOfChannels); printf("theFirstFreq = %lf\n",theFirstFreq); printf("theFreqDist = %lf\n",theFreqDist); printf("theInputFileName = %s\n",theInputFileName); printf("theInputFilePath = %s\n",theInputFilePath); printf("theOutputFileName = %s\n",theOutputFileName); printf("theOutputFilePath = %s\n",theOutputFilePath); printf("theSampleFrequency = %lf\n",theSampleFrequency); printf("theSoundFileFormat = %li\n",theSoundFileFormat); #endif // Setup the model IPEMAuditoryModel_Setup( theNumOfChannels, theFirstFreq, theFreqDist, theInputFileName, theInputFilePath, theOutputFileName, theOutputFilePath, theSampleFrequency, theSoundFileFormat); // Start processing long theResult = IPEMAuditoryModel_Process(); // Free memory for strings mxFree(theInputFileName); mxFree(theInputFilePath); mxFree(theOutputFileName); mxFree(theOutputFilePath); // Return the result to Matlab return mlfScalar(theResult); }