Delet zeros after final number
    5 views (last 30 days)
  
       Show older comments
    
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 Comment
Accepted Answer
More Answers (1)
  Mikhail
      
 on 25 Sep 2014
        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
0 Comments
See Also
Categories
				Find more on Matrix Indexing in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


