Ссылка на libmx.lib, libmat.lib, libeng.lib и включает заголовки mat.h и engine.h.Я игнорирую мнимый компонент данных и предполагаю, что вы знаете, как использовать C ++ STL.Приведенный ниже код адекватен, но здесь доступен более простой интерфейс mxWrapper: http://www.mathworks.com/matlabcentral/fileexchange/28331-replacement-for-mwarray-using-matlab-engine
vector<double> readSomeNumbers()
{</p>
<pre><code> vector<double> data;
mxArray *pMx=load("c:\\someFile.mat", "foobar");
if (!pMx) return data;
ASSERT(mxGetClassID(pMx) == mxDOUBLE_CLASS);
data.assign(mxGetPr(pMx), mxGetPr(pMx)+mxGetNumberOfElements(pMx));
mxDestroyArray(pMx);
return data;
}
mxArray *load(const string& fileName, const string& variableName)
{
MATFile *pmatFile = matOpen(fileName.c_str(), "r");
if(pmatFile == NULL)
return NULL;
mxArray* pMx = matGetVariable(pmatFile, variableName.c_str());
if(pMx == NULL)
{
matClose(pmatFile);
return NULL;
}
matClose(pmatFile);
return pMx;
}