Removing Zeros from the Beginning of a Matrix

4 vues (au cours des 30 derniers jours)
Joe
Joe le 28 Sep 2012
Commenté : PetterE le 8 Sep 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.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by