print mxArray type.
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (2)
Kaustubha Govind
am 27 Jan. 2012
The easiest way is to just have the MATLAB "disp" function do the job for you:
mexCallMATLAB(0,NULL,1, &in1, "disp");
mexCallMATLAB(0,NULL,1, &in2, "disp");
(The required header is still "mex.h", which all MEX-files need)
However, if you want to do it the old school way in C, you'll need to get the pointer to the built-in representation of the mxArrays using mxGetPr (and mxGetPi if you are dealing with a complex variable).
#include "matrix.h"
...
double *in1pr = mxGetPr(in1);
mexPrintf("in1=%f\n", in1pr[0]);
double *in2pr = mxGetPr(in2);
mexPrintf("in2=%f\n", in2pr[0]);
4 Kommentare
Mohammed Samdani
am 30 Jan. 2012
James Tursa
am 30 Jan. 2012
Did you #include "mex.h" ? What command are you using to compile the code?
Mohammed Samdani
am 30 Jan. 2012
Gauraang Khurana
am 2 Jan. 2016
Thanks Kaustubha, I was struck on this problem for almost 5hours now. I have finally printed the elements. Thanks alot.
Friedrich
am 30 Jan. 2012
0 Stimmen
Hi,
first of all, mexcallmatlab can be called from a mex file only. Since Mohammed writes an exe, this won't work.
Why are you writing an exe which uses the mxArray API? Do you use the MATLAB Engine? Or do you try to use a MATLAB Compiler generated DLL?
1 Kommentar
Mohammed Samdani
am 30 Jan. 2012
Kategorien
Mehr zu C Shared Library Integration finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!