Borrar filtros
Borrar filtros

Multiples of 5

22 visualizaciones (últimos 30 días)
Edward
Edward el 26 de Mayo de 2012
Hi, ive got an array of numbers and i want to delete the array values whose index is a multiple of 5. How can i do this?

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Mayo de 2012
for K = numel(YourArray): -1 : 1
if (K / 5) == fix(K / 5)
YourArray(K) = [];
end
end
There are definitely easier ways, but your question sounds like an assignment.
  1 comentario
Image Analyst
Image Analyst el 26 de Mayo de 2012
Other ways would be the use the rem() or mod() function.

Iniciar sesión para comentar.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 26 de Mayo de 2012
x - your array
out = x(rem(x,5) ~= 0)
  2 comentarios
Walter Roberson
Walter Roberson el 26 de Mayo de 2012
It is the _index_ whose value is a multiple of 5 that is to be affected, not according to the value of the array.
It seems likely to me that this task is homework, so I have refrained from giving the very short and simple solution.
Edward
Edward el 30 de Mayo de 2012
It wasn't but thanks anyway!

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing 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