Accessing Matlab class data member and libpointer in interfaced C code

2 次查看(过去 30 天)
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

采纳的回答

Philip Borghesani
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call C from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by