MATLAB: Sort vector elements under given restrictions

sort vector elements restrictions

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…

Best Answer

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)]