Delet zeros after final number

2 次查看(过去 30 天)
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,

采纳的回答

dpb
dpb 2014-9-25
A=A(1:find(A,1,'last'));

更多回答(1 个)

Mikhail
Mikhail 2014-9-25
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

类别

Help CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by