How to change the positions of elements in a vector?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Guillaume
2017년 5월 15일
v = [v(v ~= 3), v(v == 3)]; %assuming a row vector. If column vector replace , by ;
댓글 수: 0
kowshik Thopalli
2017년 5월 15일
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
kowshik Thopalli
2017년 5월 15일
The answer by Guillaume works. I would not have done it As elegantly as that answer
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!