如何使用 "Matlab Data / Engine API for c++" 在 c++ 中加载 .mat
How to load .mat in c++ using "Matlab Data / Engine API for c++"
我正在尝试在C++程序中包含一个.mat。但是,由于 Matlab API for C (https://de.mathworks.com/help/matlab/matlab-c-api-to-read-mat-file-data.html( 和 for C++ API (https://de.mathworks.com/help/matlab/matlab-data-array.html( 之间的内部兼容性问题,我无法使用常规"mat.h"
来执行此操作。有人知道使用新 API 实现此目的的方法吗?
提前感谢! :)
好的,我得到了一个相当欠佳的解决方案。对于那些可能也遇到这个问题的人,这是我到目前为止得到的:
#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);
如果有人为此找到更好的解决方案,请告诉我:)
相关文章:
- std::原子加载和存储都需要吗
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 为什么加载SDF会导致Mobilizer创建闭环错误
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- 如何使用tinyxml2从XML加载父实体和子实体
- 如何在C++中使用pybind11加载一个pickle python列表
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 当我尝试加载内核模块时,如何修复C++中的这个 malloc() 错误?
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- Python ctypes:不会按预期加载 dll
- 为什么会出现 gettnig 运行时错误:加载类型为"_Bit_type"(stl_bvector.h) 的空指针?
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 保存/加载大量短数组到二进制文件
- 使用 SDL2 和SDL_image C++加载图像
- 无法使用加载库卸载注入的 dll (C++)
- 是否有原子加载非原子值的函数?
- 将 bmp 文件加载到 TSpeedButton 中
- 如何使用Qt 3D库加载和显示搅拌机.obj源文件场景
- 加载与引用 .NET DLL 位于同一文件夹中的引用的 .NET DLL 时"Not found"异常