Okay, ML Compiler DLL. There is no print function available in C for the mxArray data type. One thing I use quite often in such a case is that I add a specific function to my generated DLL:
function chararray = mlprint(input)
chararray = evalc('disp(input)');
end
In that way you use the MATLAB display functionality, capture this in a char array and return it back to the C side. Once you have that char array in C, you can apply the normal printf on it.
I created a DLL with the name printtest which contains the function above. On the C side I do:
#include <stdio.h>
#include "printtest.h"
int main()
{
mxArray *test;
mxArray *out = NULL;
double data[] = {1,2,3,4,5,6,7,8,9};
if( !mclInitializeApplication(NULL,0) )
{
fprintf(stderr, "Could not initialize the application.\n");
return -1;
}
test = mxCreateDoubleMatrix(3,3,mxREAL);
memcpy(mxGetPr(test), data, 9*sizeof(double));
if (!printtestInitialize()){
fprintf(stderr,"Could not initialize the library.\n");
return -2;
}
else
{
int i = 0;
mlfMlprint(1, &out, test);
printf("%s\n",mxArrayToString(out));
mxDestroyArray(out);
out = NULL;
mxDestroyArray(test);
test = NULL;
printtestTerminate();
}
mclTerminateApplication();
return 0;
}
Best Answer