If you have an input argument v that is a row-vector and another input a, that is a scalar. How do you have a function that moves every element of v that is equal to a to the end of the vector?

 Risposta accettata

Even more generic
a=[1 2 3 4 3 2 1]
idx=a==2
b=[a(~idx),a(idx)]

Più risposte (1)

x= [1 2 3 4]
idx=2
move=@(x,ii)[x(setdiff(1:numel(x),ii)) x(ii)]
If you want to move the second number of x
out=move(x,2)

Categorie

Scopri di più su Graphics Objects in Centro assistenza e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by