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개)

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 Exchange에서 Matrix 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