how to append a matrix to the end of another matrix? (using Boost Libraries in C++)
I have this:
using namespace boost::numeric::ublas;
matrix<double> m (3, 2);
开发者_StackOverflow int k = 0;
for (int j = 0; j < m.size1 (); j++) {
for (int i = 0; i < m.size2 (); i++)
m (j, i) = k++;
}
m =
0 1
2 3
4 5
And I need to append another matrix m2 to m
matrix<double> m2 (3, 1);
k = 0;
for (int i = 0; i < m2.size2 (); i++)
m (i, 0) = k++;
m2 =
0
1
2
So, what I need to do to have this
m =
0 1 0
2 3 1
4 5 2
Where can I find more information about operations like this? I ask because the information on http://www.boost.org/doc/libs/1_43_0/libs/numeric/ublas/doc/index.htm resembles more like an API, and it has not been so useful so far.
Well, this is not elegant, but is my first try:
m.resize(m.size1(), m.size2()+1, true);
column(m, m.size2()) = column(m2, 0);
and, of course it needs to be adjusted if m2 has more than one column (or if there are differences in size1 between the two matrices)
精彩评论