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
2011 年 9 月 2 日
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 Center および File Exchange で Call C from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!