Finding the length distribution of zeros in data?

43 ビュー (過去 30 日間)
Pappis
Pappis 2025 年 9 月 2 日 13:05
編集済み: Matt J 2025 年 9 月 4 日 15:44
I have a data set of several measurements, which give me the values at given time intervals (e.g. once a minute). Every now and then, the value is missed, e.g. due to a random fault, and the missing value is marked as "0" (zero).
I have experience handling the data, but got a new request to debug the faults more closely. I need to find the length distribution of these zeros, i.e. how long the faults are typically? Are they single-value misses, or longer?
So, how do I evaluate the lengths for each of these faults, and/or their length distribution? I prefer answers without the Statictical toolbox, but if needed I have access to that, too.

採用された回答

Stephen23
Stephen23 2025 年 9 月 2 日 13:16
編集済み: Stephen23 2025 年 9 月 2 日 13:19
Fake data:
V = rand(1,123);
V(randi(123,1,23)) = 0;
V(5:7) = 0
V = 1×123
0.7107 0.4742 0.0842 0.5311 0 0 0 0.0510 0.3399 0.4221 0.8725 0.0811 0.3725 0.0362 0.9471 0.0934 0.2950 0.4100 0.0774 0.6726 0.3011 0.4228 0.9944 0.1799 0 0.5158 0.2221 0.3628 0.6641 0.0212
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
D = diff([false;V(:)==0;false]);
L = find(D<0) - find(D>0);
histogram(L)
  1 件のコメント
Pappis
Pappis 2025 年 9 月 4 日 8:37
Thank you for a very elegant solution!

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2025 年 9 月 3 日 12:13
編集済み: Matt J 2025 年 9 月 4 日 15:44
You can use this File Exchange submission,
V = rand(1,123);
V(randi(123,1,23)) = 0;
V(5:7) = 0;
[~,~,zeroLengths] = groupLims(groupTrue(~V),1);
histogram(zeroLengths)
  1 件のコメント
Pappis
Pappis 2025 年 9 月 4 日 7:29
移動済み: Rik 2025 年 9 月 4 日 7:55
I like Stephen's elegant solution very much. It's also easier to understand while reading the code. Thank you for your quick reply!

サインインしてコメントする。

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by