Removing Zeros from the Beginning of a Matrix

조회 수: 4 (최근 30일)
Joe
Joe 2012년 9월 28일
댓글: PetterE 2020년 9월 8일
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.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 9월 28일
B = A(cumsum(A,2) > 0)
  댓글 수: 2
Brandon Bihl
Brandon Bihl 2018년 9월 3일
doesnt work for negative values of A. ie. [ 0 0 -1 0 1 2 3]
PetterE
PetterE 2020년 9월 8일
Use cumsum(abs(A),2) instead.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by