Borrar filtros
Borrar filtros

Removing Zeros from the Beginning of a Matrix

7 visualizaciones (últimos 30 días)
Joe
Joe el 28 de Sept. de 2012
Comentada: PetterE el 8 de Sept. de 2020
Hi I am still fairly new to matlab and not very familiar with it yet. I was wondering how I could remove zeros from the beginning of my matrix.
i.e. A = [0 0 0 1 2 3 0 4 5] and removing the first zeros so that A becomes B where B = [1 2 3 0 4 5]
Thanks in advance for the help.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 28 de Sept. de 2012
B = A(cumsum(A,2) > 0)
  2 comentarios
Brandon Bihl
Brandon Bihl el 3 de Sept. de 2018
doesnt work for negative values of A. ie. [ 0 0 -1 0 1 2 3]
PetterE
PetterE el 8 de Sept. de 2020
Use cumsum(abs(A),2) instead.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical 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!

Translated by