开发者

vector into matrix armadillo

I want to do something similar to MATLAB's function:

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

but in armadillo c++ library,开发者_如何学Go Do you know How?.


It shouldn't be so hard to achieve similar behavior with reshape I think:

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
}

It's not exactly the same (it padds always with 0), but it's quite similar I think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜