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

采纳的回答

Fangjun Jiang
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 个)

Azzi Abdelmalek
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)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by