我知道可以通过某些方式将 matlab 矩阵加载到 C++ 程序中,但这些方式似乎都不是高效或方便的。 我看到其他人修改了'.mat'文件的标题,然后它可以直接加载到带有 Armadillo 的C++程序中。
有人知道如何修改头文件吗?
它不仅仅是将matlab ‘.mat’ 文件保存为ascii 格式。加载时间和存储空间大于二进制格式。 要存储一个 2GB 的二进制 mat 文件,我至少需要 20GB 才能将其存储为 ASCII 格式。 加载 100MB 二进制 mat 文件不到 1 秒,加载相同大小的 ASCII 文本数据需要更长的时间。
我不认为将 matlab mat 文件保存为 ASCII 格式并将其加载到 Armadillo 中是一个好的解决方案。
最佳答案
file_type can be one of the following:
...
raw_ascii:
Numerical data stored in raw ASCII format, without a header. The numbers are separated by whitespace. The number of columns must be the same in each row. Cubes are loaded as one slice. Data which was saved in Matlab/Octave using the -ascii option can be read in Armadillo, except for complex numbers. Complex numbers are stored in standard C++ notation, which is a tuple surrounded by brackets: eg. (1.23,4.56) indicates 1.24 + 4.56i.
因此,您应该能够使用以下代码加载以文本格式编写的 Matlab 矩阵,该矩阵包含在名为“MatlabMatrix.mat”的文件中:
arma::mat fromMatlab;
fromMatlab.load("MatlabMatrix.mat", arma::raw_ascii);
还有一个相关的问题可以找here .
关于c++ - 如何用 Armadillo 加载matlab矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22903242/