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?
조회 수: 1 (최근 30일)
이전 댓글 표시
For example,
x= move ([1 2 3 4], 2), i want x to equal to [1 3 4 2]
thanks an advance
댓글 수: 0
채택된 답변
Fangjun Jiang
2016년 8월 9일
편집: Stephen23
2017년 5월 6일
Even more generic
a=[1 2 3 4 3 2 1]
idx=a==2
b=[a(~idx),a(idx)]
댓글 수: 1
Stephen23
2017년 5월 6일
I accepted this answer as it obviously solves the problem, and does so in a very neat way.
추가 답변 (1개)
Azzi Abdelmalek
2016년 8월 9일
편집: Azzi Abdelmalek
2016년 8월 9일
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!