|
hi all,
I'm trying to use a C++ DLL to do some computing, and return a cell array X to the matlab code.
The elements inside the cell array have the same data type but different size.
e.g. Cell array X(2*3)
X={{[]},{[2,3]},{[]};
{[5]},{[]},{[1]} }
I've considered 2 ways:
1. Initialize arrays inside the dll code, use the concept of multilevel pointer, and return a pointer
problem: you have to set the size of a new array in C++,e.g. A[][5]. However, the size of the array varies, and it is not a constant.
e.g.
double *mydll()
{
double A[10];
doube *B[2];
double **C[1];
.....
.....
.....
return C;
}
2. create an empty cell array in matlab code, and pass a pointer of the cell array to the DLL. DLL updates the values of the elements of the cell array.
problem: cell array in matlab is actually a collection of pointers, and the adresses of the pointers are not continuous. We cannot use function libpointer to find a single pointer pointing to the cell array.
e.g.
loadlibrary mylib myheader.h
myCellArray=cell(100,200);
myPtr=libpointer('doublePtr',myCellArray); % error msg
calllib('mylib ','myheader.h', myPtr);
newCellArray=get( myPtr,'Value');
unloadlibrary mylib;
Anyone knows how to solve these problems? or have a better way to do it?
Thanks~
|