sort vector elements under given restrictions
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi guys,
i have the vector v=[1 2 3 4 5]
wanna resort it so that v(3) and v(5) comes first:
v=[3 5 others] % 'others' has any order
How can i do that? The problem here is exactly this: how to write 1:5 but missing 3 and 5 .
Any idea? thx...
-----------------------------------------------------------------------------------------
PS: this question is related to
The point relating to this cited question is that i can find all combinations (just for-loop), but i cannot arrange the rest of the dimensions. Thus this present question.
Thx...
0 comentarios
Respuesta aceptada
zepp
el 19 de Mzo. de 2014
You can create a logical array (same length as v) with 1's for the positions you want (say, 3 and 5) and 0's for the rest and use that to refer to the indices.
v = [1 2 3 4 5]
ind = [0 0 1 0 1]
v = [v(ind==1) v(~ind==1)]
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!