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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!