how to remove unwanted zeros from a vector
Afficher commentaires plus anciens
I have a column vector of the type [ 0 0 0 0 4 5 6 0 0 0 9 9 8 7 6 0 0 0 0 0 0 3 4 4 0 0 0]
Want to remove unwanted zeros to get the form [ 0 4 5 6 0 9 9 8 7 6 0 3 4 4 0]
i -e I don't wana remove all zeros or zeros in the beginning and end. find will not work I guess:
Réponse acceptée
Plus de réponses (2)
Azzi Abdelmalek
le 22 Juin 2016
a=[ 0 5 0 0 0 0 4 5 6 0 0 0 9 9 8 0 7 6 0 0 0 0 0 0 3 4 4 0]
idx=a==0
ii1=strfind([0 idx],[0 1])
ii2=strfind([idx 0],[1 0])
idy=[];
for k=1:numel(ii1)
idy=[idy ii1(k)+1:ii2(k)]
end
a(idy)=[]
1 commentaire
BlueBird
le 23 Juin 2016
Andrei Bobrov
le 23 Juin 2016
out = v(v | [1,v(1:end-1)])
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!