フィルターのクリア

Removing Zeros from the Beginning of a Matrix

7 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by