犰狳读取MAT文件错误

Armadillo reading MAT file error

本文关键字:文件 错误 MAT 读取      更新时间:2023-10-16

我目前正在Visual Studio环境中使用Armadillo将MATLAB代码转换为C++进行BeagleBone Black交叉编译。

这是一个信号处理项目,所以我需要一种方法来读取和写入二进制数据文件,特别是 .mat 文件。值得庆幸的是,犰狳文档说您可以使用.load((将.mat文件直接加载到矩阵中。

我一开始尝试过,但似乎它没有正确读取文件,也没有读取所有条目。我的参考文件是一个 2000x6 矩阵,创建的犰狳矩阵是 5298x1。我知道如果没有犰狳模仿标题,它将被转换为列向量,我需要使用 .reshape(( 重塑它,但它根本没有收到所有条目,并且通过检查,它确实读取的条目是错误的。

我不确定问题是什么。我已将数据引用 .mat 文件放在 BBB 上远程项目的 Debug 文件夹中,其中创建了 .out 编译文件。有没有其他方法应该集成它?

此外,欢迎帮助模仿犰狳头或其他建议。 如果您需要什么,请告诉我。

这是我正在使用的测试程序:

#include <iostream>
#include <armadillo>
using namespace std;
using namespace arma;
int main()
{
mat data_ref;
data_ref.load("Epoxy_6A_Healthy_Output_200kHz_Act1_001.mat");
cout << "For Data_ref, there are " << data_ref.n_cols << " columns and " << data_ref.n_rows << " rows.n";
cout << "First item: " << data_ref(0) << "n6th item: " << data_ref(6) << "n2000th item: " << data_ref(2000);
data_ref.reshape(2000, 6);
cout << "For Data_ref, there are " << data_ref.n_cols << " columns and " << data_ref.n_rows << " rows.n";
cout << "First item: " << data_ref(0,0) << "nLast Item: " << data_ref(1999,5);
cout << "nDone";
return 0;
}

.mat 文件中的第一个元素是 0.0,最后一个元素是 0.0014。 这是输出。

For Data_ref, there are 1 columns and 5298 rows.
First item: 8.48749e-53
th item: 9.80727e+256
th item: -2.4474e+238For Data_ref, there are 6 columns and 2000 rows.
First item: 8.48749e-53
(gdb) 1028-var-list-children --simple-values "var4.public" 0 1000
(gdb) 1030-var-list-children --simple-values "var4.arma::Base<double, 
arma::Mat<double> >" 0 1000
Last Item: 0
Done=thread-exited,id="1",group-id="i1"
The program '' has exited with code 0 (0x0).

谢谢

犰狳不支持Matlab的.mat格式。在文档中,他们以二进制格式引用犰狳mat。但是,您可以使用hdf5二进制格式将数据保存在 Matlab 中并将其导入犰狳,但随后您必须下载 hdf5 库并重新配置犰狳。请参阅文档中的hdf5_binary部分。