Accessing Matlab class data member and libpointer in interfaced C code

2 visualizaciones (últimos 30 días)
Hello!
I have a MEX-function to which I pass either a normal matrix or a Matlab class instance where one of the data members is a libpointer object.
I want my MEX function to access this libpointer object, if the object is indeed an instance of my class.
Hence the following questions:
1. If I determine that the object is in fact an object of my class (by calling mxGetClassName and comparing strings), how can I access a certain data member of the class? In this case the libpointer.
2. Say that I get I got hold of the Matlab expression holding the libpointer, how can I extract the address in MEX? mxGetPr doesn't seem to work. I managed to work out a workaround, by writing a small m-function and calling mexCallMATLAB and this works but is there some way to do this from C? This is in a very time critical part of the code.
Best, Joel
  1 comentario
Joel Andersson
Joel Andersson el 1 de Sept. de 2011
To clarify: For the second part, what I want is to access the "value" field of the libpointer from C.

Iniciar sesión para comentar.

Respuesta aceptada

Philip Borghesani
Philip Borghesani el 2 de Sept. de 2011
You need to use the function mxGetProperty. R2011a or later is required for this function to work properly, because of the type of objects used to implement libpointers.
C++ pseudocode:
mxArray *value=mxGetProperty(lib_pointer,0,"value");
void *ptr=mxGetData(value); // change data type to suite
This will only work for arrays basic data types there is no good solution for structures.

Más respuestas (0)

Categorías

Más información sobre Call C from MATLAB 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!

Translated by