2017-07-03 36 views
1

我目前在Visual Studio環境中使用Armadillo將BeagleBone Black編譯成C++。犰狳讀MAT文件錯誤

這是一個信號處理項目,所以我需要一種讀取和寫入二進制數據文件,特別是.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). 

感謝

+0

您應該提供一個[MCVE],其中包含用於加載矩陣,輸入矩陣,輸出和期望輸出的代碼 – Rama

回答

1

犰狳不支持Matlab的.MAT格式。在文檔中他們指的是Armadillo mat二進制格式。然而,您可以使用hdf5二進制格式將數據保存在Matlab中,並將其導入到Armadillo中,但是必須下載hdf5庫並重新配置Armadillo。請參閱文檔中的hdf5_binary部分。