Accessing Matlab class data member and libpointer in interfaced C code

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Joel Andersson
Joel Andersson il 1 Set 2011
To clarify: For the second part, what I want is to access the "value" field of the libpointer from C.

Accedi per commentare.

Risposta accettata

Philip Borghesani
Philip Borghesani il 2 Set 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.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by