MATLAB: Print mxArray type.

printing mxarray datatype

Hi,
I want to know how to print mxArray data type. I have a program below
int main(int ac, const char *av[]) {
int param1 = atoi(av[1]); int param2 = atoi(av[2]);
mxArray *in1 = NULL, *in2= NULL;
printf(" input param1 = %d\n", param1); printf(" input param2 = %d\n", param2);
in1 = mxCreateDoubleScalar(param1); in2 = mxCreateDoubleScalar(param2);
}
I want to know how to print in1 & in2
I also want to know how to print mxArray type, if mxArray was string , array , matrix or struct.
If a I have to use any function for this which header file should I include in my .c file
Thansk in advance

Best Answer

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;
}