Use an array of Matlab cells in a C / C ++ program

How can I read the array of Matlab cells stored as a .mat file and having 3 * 3 * 2 multidimensional double data in an ac / C ++ array?

+3
source share
3 answers

The MATLAB file format is described here . Doesn't look too hairy.

Edit: Sorry, the link is broken.

+1
source

libmx.lib, libmat.lib, libeng.lib mat.h engine.h. , , ++ STL. , mxWrapper: http://www.mathworks.com/matlabcentral/fileexchange/28331-replacement-for-mwarray-using-matlab-engine

vector<double> readSomeNumbers() {

    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;
}

>

+1

This document describes an interface for reading and writing MAT files in C / C ++:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f39876.html#f13830

0
source

Source: https://habr.com/ru/post/1730274/


All Articles