2

我想做一些类似于MATLAB's 功能的事情:

mat = vec2mat(vec,matcol)
mat = vec2mat(vec,matcol,padding)
[mat,padded] = vec2mat(...) 

但是在犰狳 c++ 库中,你知道怎么做吗?

4

1 回答 1

4

我认为通过 reshape 实现类似的行为应该不难:

mat vec2mat(vec V, size_t cols) {
    size_t rows = std::ceil(V.n_elems / double(cols));
    return V.reshape(cols, rows);// return the original vector as matrix
}

它不完全相同(它总是用 0 填充),但我认为它非常相似。

于 2012-03-06T07:57:01.620 回答