How to change the positions of elements in a vector?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi all, I need to find all the components of a vector that are equal to 3 and move them at the end of the vector. Any suggestion? Thanks
0 Commenti
Risposte (2)
Guillaume
il 15 Mag 2017
v = [v(v ~= 3), v(v == 3)]; %assuming a row vector. If column vector replace , by ;
0 Commenti
kowshik Thopalli
il 15 Mag 2017
Using the find() function you can do this very easily.
[R,c]= find(myVector==3)
This gives you the positions of the elements which are equal to 3. Once you have this you can easily reorder. Hope this helps
2 Commenti
kowshik Thopalli
il 15 Mag 2017
The answer by Guillaume works. I would not have done it As elegantly as that answer
Vedere anche
Categorie
Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!