【问题标题】:append rows to armadillo .mat file将行附加到犰狳 .mat 文件
【发布时间】:2017-09-28 18:36:10
【问题描述】:

有没有办法将行追加到使用 .save() 函数保存的 .mat 文件中?

例如在下面的 for 循环中:

mat M; M.ones(1,5);

    for (int i=0; i<5; i++) {
        mat tmp;
        tmp = M + i;
        tmp.save("file.mat", arma_ascii) // + some code to append rather than overwrite;
    }

我的想法是我可以避免将数据作为大型矩阵存储在我的工作区中。有什么想法吗?

谢谢

【问题讨论】:

    标签: c++ save armadillo


    【解决方案1】:

    save() 函数只覆盖文件。您可以使用以下代码附加到文本文件,例如使用具有相同列数的行向量:

        ofstream outfile;
        outfile.open("file.mat", std::ios::app);
        outfile << myRowVector;
        oufile.close();
    

    自动添加换行符。 std::ios::app 用于附加到文件。

    【讨论】:

      【解决方案2】:

      您可以使用.insert_rows().insert_cols() 方法从mat 追加行/列。见here

      【讨论】:

        猜你喜欢
        • 2017-12-06
        • 1970-01-01
        • 2015-10-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多