edgarmtze
edgarmtze

Reputation: 25048

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, Do you know How?.

Upvotes: 2

Views: 3745

Answers (1)

Pawel Zubrycki
Pawel Zubrycki

Reputation: 2713

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.

Upvotes: 4

Related Questions