number of special array in a table

1 次查看(过去 30 天)
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

采纳的回答

Guillaume
Guillaume 2019-2-5
编辑:Guillaume 2019-2-5
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by