From: David Doria <daviddoria@gm...> - 2009-07-15 16:42:57
There is a matlab function reshape() that lets you "wrap" or "reshape"
a vector into a matrix. I did not see anything like this in VNL (maybe
I missed it?). If so, maybe something like this can be added
(templated, of course)?
vnl_matrix<double> Reshape(const vnl_vector<double> &V, const
unsigned int rows, const unsigned int cols)
//This function reshapes a vector into a matrix using row major construction.
//check input sizes
if(V.size() != rows*cols)
std::cout << "Data sizes do not match!" << std::endl;
vnl_matrix<double> M(rows, cols);
unsigned int counter = 0;
for(unsigned int r = 0; r < rows; r++)
for(unsigned int c = 0; c < cols; c++)
M(r,c) = V[counter];
From: David Doria <daviddoria@gm...> - 2009-07-16 11:04:34
On Thu, Jul 16, 2009 at 4:53 AM, Ian
> Why can't you use
> unsigned r, c;
> vnl_vector<double> vec(r*c);
> vnl_matrix<double> my_mat(vec.data_block(), r, c);
I guess you can! But maybe a wrapper would help - this seems like
something a user (me) would much more easily recognize:
vnl_matrix<double> my_mat = vec.reshape(r,c);
Instead of relying on finding the (block,r,c) matric constructor as
well as the data_block() vector function.
Just a thought.