Boost logo

Boost Users :

From: Alexander Schmolck (a.schmolck_at_[hidden])
Date: 2007-10-19 09:42:57


Hi,

If I have a boost::numeric::ublas::vector<double> v, I can use the STL's sort
and boost::lambda.

 sort(v.begin(), v.end(), _1<_2);

How do I do the same with matrix<double>, using, say column 3 as sort key
(i.e. I want to reorder the rows in the matrix by their 3rd entry)?

 sort(m.begin1(), m.end1(), _1[3]<_2[3]);

won't do the trick, and I really have a hard time figuring out what does.

In case it's not clear what I want, here's an example:

[0,0,1,4
 0,0,2,3
 0,0,3,2
 0,0,4,1]

=>

[0,0,4,1
 0,0,3,2
 0,0,2,3
 0,0,1,4]

cheers,

'as


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net