Filter löschen
Filter löschen

number of special array in a table

1 Ansicht (letzte 30 Tage)
Abo
Abo am 5 Feb. 2019
Kommentiert: Guillaume am 5 Feb. 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

Akzeptierte Antwort

Guillaume
Guillaume am 5 Feb. 2019
Bearbeitet: Guillaume am 5 Feb. 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 Kommentare
madhan ravi
madhan ravi am 5 Feb. 2019
+1 , one closing paranthesis ")" is missing before numel()
Guillaume
Guillaume am 5 Feb. 2019
Thanks, fixed.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by