【问题标题】:How to load .mat in c++ using "Matlab Data / Engine API for c++"如何使用“C++ 的 Matlab 数据/引擎 API”在 C++ 中加载 .mat
【发布时间】:2018-05-03 19:39:08
【问题描述】:

我正在尝试在 C++ 程序中包含一个 .mat。但是,由于 C 的 Matlab API (https://de.mathworks.com/help/matlab/matlab-c-api-to-read-mat-file-data.html) 和 C++ (https://de.mathworks.com/help/matlab/matlab-data-array.html) 之间的内部兼容性问题,我无法使用传统的 "mat.h" 来执行此操作。有人知道使用新 API 实现此目的的方法吗?

提前致谢! :)

【问题讨论】:

    标签: c++ matlab


    【解决方案1】:

    好的,我得到了一个不太理想的解决方案。对于那些也可能遇到这个问题的人,这是我到目前为止得到的:

    #include "MatlabDataArray.hpp"
    #include "MatlabEngine.hpp"
    
        using namespace matlab::engine;
        // Start MATLAB engine synchronously
        std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB();
        std::vector<double> labels_cpp;
    
        // Create figure window
        matlabPtr->eval(convertUTF8StringToUTF16String("m = matfile('labelsOfGist.mat'); labels = m.labels;"));
    
        //Get figure handle and Units property
        matlab::data::ArrayFactory factory;
        matlab::data::TypedArray<double> labels = matlabPtr->
            getVariable(convertUTF8StringToUTF16String("labels"));
    
        size_t elements = labels.getNumberOfElements();
        labels_cpp.reserve(elements);
        std::insert_iterator<std::vector<double>> insert_it(labels_cpp, labels_cpp.begin());
        std::copy(labels.begin(),labels.end(), insert_it);
    

    如果有人对此有更好的解决方案,请告诉我:)

    【讨论】:

    • 这确实看起来不太理想,需要连接到 MATLAB。 C++ 数据接口是非常新的。也许他们还没有开始添加 MAT 文件读取?
    • 是的,这可能是个问题:/
    猜你喜欢
    • 1970-01-01
    • 2016-08-17
    • 2020-10-12
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    相关资源
    最近更新 更多