Registered Member
|
Hi
This seems so trivial, but I cannot figure out how to do it: I have a vector v = [ 1 2 3 4 5 ]', and would like to reorder the elements, e.g. Have the 3 last elements be v(1:3), and the first two become v(4:5). in matlab, I could do v = [ v(3:end); v(1:2) ]. If I simply try:
I get aliasing (as would be expected). This works:
but is really ugly. Is there a simple way to copy/replace elements like that? Thanks! |
Moderator
|
You can build a PermutationMatrix:
PermutationMatrix<Dynamic,Dynamic> p(5); p.indices() << 3,4,0,1,2; v = p*v; |
Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]