2017-04-05 81 views
0

我使用犰狳來獲取矩陣,但似乎它給了我關於cols和行的錯誤數字。犰狳n_rows不起作用

第一張圖片我有一個叫做se的30x30矩陣。我打印行數和列數。然後我將se放入一個名爲Acqui的函數中,並打印該函數中的行和列。

//define 'mat se' as a 30 by 30 matrix and give it certain value 
printf("%u \n",se.n_rows); 
printf("%u \n",se.n_cols); 
NextP=Acqui(se,arr_sample,Maxu,SamTraPoi); 

然後在Acqui功能,我做到以下幾點:

Acqui(mat &se,mat &arr_sample,mat &Maxu,mat &SamTraPoi); 
{ 
    int num=se.n_rows; 
    int col=se.n_cols; 
    printf("%d \n", num); 
    printf("%d \n", col); 
    //other program 
} 

我得到了以下的結果,列900,不正確的。

result

Acqui我什麼也沒做只是使用引用傳遞的價值。如果我在Acqui改變類似於下面的代碼,結果將改變

Acqui(mat &se,mat &arr_sample,mat &Maxu,mat &SamTraPoi) 
{ 
    int num=se.n_rows; 
    int col=se.n_cols; 
    printf("%llu \n", se.n_rows); 
    printf("%llu \n", se.n_cols); 
    //other programm 
} 

result

現在該行成爲一個非常大的數字。當然結果應該是四個30.

事實上,我的程序在幾天前成功運行。在這些日子裏,我安裝了一個新的軟件到我的Ubuntu,並發現它佔用了我的磁盤空間,所以我只是卸載它。我什麼也沒做。

回答

0

這樣解決得太快了...... 事實上,在我跑過程序之前我做了另一個修改,我認爲它沒有問題。 當我在製作文件之前,編譯代碼,我只是用克++而不是鏈接到C++ 11像下面

g++ samplecode.cpp -o samplecode -O2 -larmadillo 

現在,因爲我需要在C中使用函數++ 11所以我需要改變使文件到

g++ -std=c++11 samplecode.cpp -o samplecode -O2 -larmadillo 

然後,我運行程序犰狳將無法正常工作。所以我要刪除

-std=c++11 

的suprising的事情是,代碼仍然有效,即使我添加函數需要C++ 11。我需要使用的函數是erfc()。它應該只在鏈接到C++ 11時才起作用。無論如何,這個問題似乎解決了