Use mexCallMATLAB inside of a C-Function only passing pointers
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone,
inside of a mexFunction, I want (i. e. my specifications are) to call a C-function myfcn(), and inside of myfcn() I want to use mexCallMATLAB.
The arguments passed to myfcn all are pointers, like
myfcn(double *ptr1, double *ptr2, int *ptr3, ...)
and so on. As I unterstood, to use mexCallMATLAB I have to store the necessary information in variables of type mxArray.
My question now is, how can I set up the mxArrays I need as in
array1 = mxCreateDoubleArray(m, n, mxREAL);
memcpy(array1, ptr1, sizeof(double) * m * n);
since from my specifications it is neither possible to pass additional parameters for m and n to myfcn(), nor to pass arguments different from pointers which do not allow me to determine the size of the arrays they're pointing to.
Is there another possibility of solving this problem than e. g. extending the array and storing their length in additional fields (which is what I not really want to do because the structure of the data in fact is fixed, too), but maybe something like using mexCallMatlab with different inputs, or setting up the mxArray in some other clever way?
Thank you very much for your support!
Adrian Buerger
2 comentarios
Titus Edelhofer
el 8 de Ag. de 2013
Hi Adrian,
if at all this question can be answered, then only if you "know" inside your myfcn the size of ptr1[] etc. The code in myfcn, how does it know the array bounds? It somehow needs to know, either by passing the size, or as constants or what so ever. Just looping over the array until you get a memory failure is probably not the best way ;-).
Titus
Respuesta aceptada
Jan
el 8 de Ag. de 2013
This sounds magic. When your function obtains pointers as inputs without specifying the dimensions of the arrays, how can the function determine the length of the arrays?
This cannot work:
array1 = mxCreateDoubleArray(m, n, mxREAL);
% memcpy(array1, ptr1, sizeof(double) * m * n); ERROR!
Better:
memcpy(mxGetPr(array1), ptr1, sizeof(double) * m * n);
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!