犰狳n_rows不起作用

时间:2017-04-05 04:03:38

标签: c++ armadillo

我使用犰狳来获取矩阵,但似乎它给了我关于cols和row的错误数字。

第一张图片我有一个名为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上安装了一个新软件,发现它耗尽了我的磁盘空间,所以我只是卸载它。我什么也没做。

1 个答案:

答案 0 :(得分:0)

这解决得这么快...... 事实上,在我运行上面的程序之前我做了另一个修改,我认为这没有问题。  当我在Make文件中编译代码之前,我只使用g ++而不是像下面的

那样链接到c ++ 11
g++ samplecode.cpp -o samplecode -O2 -larmadillo

现在因为我需要在c ++ 11中使用一个函数所以我需要将make文件更改为

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

然后我运行了犰狳赢得的计划。所以我必须删除

-std=c++11

令人惊讶的是,即使我添加函数需要c ++ 11,代码仍然有效。我需要使用的函数是erfc()。它应该只在链接到c ++ 11时有效。无论如何问题似乎已经解决了