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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Alexandra Huff
el 9 de Ag. de 2016
For example,
x= move ([1 2 3 4], 2), i want x to equal to [1 3 4 2]
thanks an advance
0 comentarios
Respuesta aceptada
Fangjun Jiang
el 9 de Ag. de 2016
Editada: Stephen23
el 6 de Mayo de 2017
Even more generic
a=[1 2 3 4 3 2 1]
idx=a==2
b=[a(~idx),a(idx)]
1 comentario
Stephen23
el 6 de Mayo de 2017
I accepted this answer as it obviously solves the problem, and does so in a very neat way.
Más respuestas (1)
Azzi Abdelmalek
el 9 de Ag. de 2016
Editada: Azzi Abdelmalek
el 9 de Ag. de 2016
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 comentarios
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!