Borrar filtros
Borrar filtros

How can I rearrange a vector?

3 visualizaciones (últimos 30 días)
Jeah MK
Jeah MK el 15 de Feb. de 2022
Comentada: Jeah MK el 15 de Feb. de 2022
I have a vector
a = [9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9];
How can I rearrage it to
a = [0 0 0 0 0 4 3 2 1 0 1 2 3 4 0 0 0 0 0];
Thank you!

Respuesta aceptada

Jan
Jan el 15 de Feb. de 2022
Editada: Jan el 15 de Feb. de 2022
Some bold guesses of what you want to achieve:
aa = [9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9];
a = aa;
a(a >= 5) = 0
a = aa;
a(~ismember(a, 1:4)) = 0
a = aa;
a(ismember(a, 5:9)) = 0
a = aa;
a([1:5, end-4:end]) = 0
a = aa;
n = numel(a);
a(abs((1:n) - (n + 1)/2) >= 5) = 0
There is an infinite number of methods to produce the wanted output based on the given input. The current explanations are not enough to find the general solution.
  1 comentario
Jeah MK
Jeah MK el 15 de Feb. de 2022
Thank you! The first one works pretty well!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by