c++ - 如何用 Armadillo 加载matlab矩阵?

标签 c++ matlab armadillo

我知道可以通过某些方式将 matlab 矩阵加载到 C++ 程序中,但这些方式似乎都不是高效或方便的。 我看到其他人修改了'.mat'文件的标题,然后它可以直接加载到带有 Armadillo 的C++程序中。

有人知道如何修改头文件吗?

它不仅仅是将matlab ‘.mat’ 文件保存为ascii 格式。加载时间和存储空间大于二进制格式。 要存储一个 2GB 的二进制 mat 文件,我至少需要 20GB 才能将其存储为 ASCII 格式。 加载 100MB 二进制 mat 文件不到 1 秒,加载相同大小的 ASCII 文本数据需要更长的时间。

我不认为将 matlab mat 文件保存为 ASCII 格式并将其加载到 Armadillo 中是一个好的解决方案。

最佳答案

根据Armadillo documentation :

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/

相关文章:

c++ - “ChaCha”尚未使用 Crypto++ 在此范围内声明?

c++ - 有没有办法在不知道 c++ 中的大小的情况下迭代枚举

matlab - 多行 fprintf() 每行使用每个数组中的一个元素

C++ Armadillo : double for loop using iterators

c++ - 辅助网络接口(interface)上的Linux C/C++ UDP服务器

C++ map 定义基础

matlab - 在 Matlab 中测试 float 是否为整数

java - OpenCV 和 Matlab 使用 DFT 实现信号相关的区别

c++ - 复杂稀疏矩阵A的 Armadillo eigs_sym(A,k)

c++ - Rcpp Armadillo : Lambda expression with each_slice