【问题标题】:Armadillo reading MAT file error犰狳读取 MAT 文件错误
【发布时间】:2017-12-06 20:59:12
【问题描述】:

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

这是一个信号处理项目,所以我需要一种方法来读写二进制数据文件,特别是 .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).

谢谢

【问题讨论】:

标签: c++ visual-studio beagleboneblack armadillo mat-file


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多