print mxArray type.
显示 更早的评论
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
采纳的回答
更多回答(2 个)
Kaustubha Govind
2012-1-27
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 个评论
Mohammed Samdani
2012-1-30
James Tursa
2012-1-30
Did you #include "mex.h" ? What command are you using to compile the code?
Mohammed Samdani
2012-1-30
Gauraang Khurana
2016-1-2
Thanks Kaustubha, I was struck on this problem for almost 5hours now. I have finally printed the elements. Thanks alot.
Friedrich
2012-1-30
0 个投票
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?
类别
在 帮助中心 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!