gpt4 book ai didi

c++ - Armadillo 读MAT文件报错

转载 作者:行者123 更新时间:2023-11-30 05:11:49 38 4
gpt4 key购买 nike

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

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

我一开始尝试过,但它似乎没有正确读取文件,也没有读取所有条目。我的引用文件是一个2000x6的矩阵,创建的 Armadillo 矩阵是5298x1。我知道如果没有一个模仿 Armadillo 的 header ,它将被转换成一个列 vector ,我将需要使用 .reshape() 对其进行整形,但它根本没有收到所有条目,通过检查,它确实收到了条目读错了。

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

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

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

#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).

谢谢

最佳答案

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

关于c++ - Armadillo 读MAT文件报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44888146/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com