From: Marc Bernau on
Hi Dean,

two-dimensional matrices work. So far I didn't find out how three-dimensional matrices work (e.g. colour images). You need to create the 2D-array in your COM software in such a way:

HRESULT hr;
SAFEARRAY *pSA;
float HUGEP *pFLOAT;

SAFEARRAYBOUND aDim[2]; // two dimensional array
aDim[0].lLbound= 0;
aDim[0].cElements= size_y; // Matlab needs y first, then x
aDim[1].lLbound= 0;
aDim[1].cElements= size_x; // rectangular array
pSA= SafeArrayCreate(VT_R4,2,aDim); // again, 2 dimensions //VT_R4 for single //VT_R8 for double; VT_UI1 for BYTE;

hr = SafeArrayAccessData(pSA, (void HUGEP* FAR*)&pFLOAT);
// copy your stuff to pFLOAT now
SafeArrayUnaccessData(pSA);

VariantInit(matrix);
matrix->vt= VT_ARRAY | VT_R4; //VT_R8 for double; VT_UI1 for BYTE;
matrix->parray= pSA;

Your return value to matlab is VARIANT* matrix;

Hope it works yor you.

Marc