Effacer les filtres
Effacer les filtres

Count Zeros Length Matrix Into an Array

1 vue (au cours des 30 derniers jours)
Angga Lisdiyanto
Angga Lisdiyanto le 18 Jan 2016
I want to get all length of zero values alternately and consecutively. In example :
m = [0 0 0 0 1 2 2 0 0 5 3 4 5 0 0 0 0 0 9 9 0 0 0];
Result that i need is : zero = [4 2 5 3]
So, i need to count the 0 values in each of alternately. Thanks in advance.

Réponse acceptée

Stephen23
Stephen23 le 18 Jan 2016
>> m = [0 0 0 0 1 2 2 0 0 5 3 4 5 0 0 0 0 0 9 9 0 0 0];
>> x = find(diff([false,m==0,false]));
>> x(2:2:end)-x(1:2:end)
ans =
4 2 5 3
  1 commentaire
Angga Lisdiyanto
Angga Lisdiyanto le 18 Jan 2016
Modifié(e) : Angga Lisdiyanto le 18 Jan 2016
Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by