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!