犰狳读取MAT文件错误 [英] Armadillo reading MAT file error
问题描述
我目前正在使用Armadillo在Visual Studio环境中对BeagleBone Black进行交叉编译,以将MATLAB代码转换为C ++.
I'm currently cross-compiling on the BeagleBone Black in a Visual Studio environment using Armadillo to translate MATLAB code into C++.
这是一个信号处理项目,因此我需要一种读写二进制数据文件(特别是.mat文件)的方法.值得庆幸的是,犰狳文档说,您可以使用.load()直接将.mat文件加载到矩阵中
This is a signal processing project, so I need a way to read and write binary data files, specifically .mat files. Thankfully, the armadillo documentation says that you can load .mat files directly into a matrix using .load()
我一开始尝试过,但是似乎没有正确读取文件,也没有读取所有条目.我的参考文件是2000x6矩阵,创建的犰狳矩阵是5298x1.我知道,如果没有模仿犰狳的标题,它将被转换为列向量,我将需要使用.reshape()对其进行整形,但它只是不接收所有条目,并且通过检查,它确实收到了条目读错了.
I attempted that at first, but it seems like it's not reading the file correctly, nor is it reading all the entries. My reference file is a 2000x6 matrix, and the created armadillo matrix is 5298x1. I know that without an armadillo-mimicking header, it will be converted into a column vector and I will need to reshape it using .reshape(), yet it simply isn't receiving all the entries, and by inspection, the entries it did read are wrong.
我不确定是什么问题.我已将数据参考.mat文件放在BBB上远程项目的Debug文件夹中,在其中创建.out编译文件.我还有其他方法可以整合它吗?
I'm not sure what the problem is. I've placed the data reference .mat files in the Debug folder for the remote project on the BBB, where the .out compiled file is created. Is there another way I should integrate it?
此外,欢迎模仿犰狳头的帮助或其他建议. 如果您需要任何东西,请告诉我.
Also, help with mimicking the armadillo header or other suggestions are welcome. If you need anything, please let me know.
这是我正在使用的测试程序:
Here is the test program I am using:
#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. 这是输出.
The first element in the .mat file is 0.0, and the last element is 0.0014. Here is the output.
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 lib并重新配置Armadillo.请参阅文档中的hdf5_binary
部分.
Armadillo does not support Matlab's .mat format. In the documentation they refer to the Armadillo mat
binary format. You may however save the data in Matlab using the hdf5
binary format and import it into Armadillo but then you have to download the hdf5 lib and reconfigure Armadillo. See the hdf5_binary
section in the documentation.
这篇关于犰狳读取MAT文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!