Dear all, I'm looking for an efficient way to delete zeros after final number in MATLAB,
A= [ 5 6 0 3 2 0 9 0 0 0 0 0 0]
B = [ 5 6 0 3 2 0 9]
Thank you so much,

1 件のコメント

Stephen23
Stephen23 2014 年 9 月 26 日
Technically speaking, zero is also a number...

サインインしてコメントする。

 採用された回答

dpb
dpb 2014 年 9 月 25 日

2 投票

A=A(1:find(A,1,'last'));

1 件のコメント

Mahsa
Mahsa 2014 年 9 月 25 日
It works, that you so much

サインインしてコメントする。

その他の回答 (1 件)

Mikhail
Mikhail 2014 年 9 月 25 日

0 投票

There are plenty of ways to do that. For instance, find(A) will find indexes of all nonzero elements. So you can write:
B= A(1:max(find(A)))
max(find(A)) - index of the last nonzero element in A

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2014 年 9 月 25 日

コメント済み:

2014 年 9 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by