Delete the front zero elements from vector

Hello everyone
I want to delete the front zero element from vector. I receive a input vector, for example,
a=[0 0 0 2 4 0 8 9 0 3]
how can I get
a=[2 4 0 8 9 0 3]
Thank you
Famuto

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 26 Nov 2013
Modifié(e) : Azzi Abdelmalek le 26 Nov 2013
a=[0 0 0 2 4 0 8 9 0 3]
a(cumsum(abs(a))==0)=[]
or
a=a(find(a~=0,1):end)

Cette question est clôturée.

Tags

Aucun tag saisi pour le moment.

Question posée :

le 26 Nov 2013

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by