number of special array in a table

1 vue (au cours des 30 derniers jours)
Abo
Abo le 5 Fév 2019
Commenté : Guillaume le 5 Fév 2019
Hi,
I have a table (100*1) contains different number of "2" (see the following image) and "NAN" which changing dynamically. the question is how can I count number of "2" before each "NAN"?
regrds

Réponse acceptée

Guillaume
Guillaume le 5 Fév 2019
Modifié(e) : Guillaume le 5 Fév 2019
It doesn't look like you have a table. It looks like a plain vector.
Anyway,
lengthofruns = diff([1; find(isnan(yourvector)); numel(yourvector)])
Basically, find the position of all the nans, then take the difference between consecutive positions to know the lengths of the runs.
  2 commentaires
madhan ravi
madhan ravi le 5 Fév 2019
+1 , one closing paranthesis ")" is missing before numel()
Guillaume
Guillaume le 5 Fév 2019
Thanks, fixed.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by