フィルターのクリア

Data gap finding in a time series

10 ビュー (過去 30 日間)
Binu
Binu 2020 年 4 月 20 日
編集済み: Adam Danz 2024 年 2 月 23 日
Hello,
The attached file has two columns, time and levels. It has 6 missing data gaps. I want to find the index of each gap like this;
gap1 index 7-13
gap2 index 38-42
gap3 index 67-81
gap4 index 108-111
gap5 index 141-151
gap6 index 182-184
Your help is highly appreciated.
Thank you
Dash

採用された回答

Adam Danz
Adam Danz 2020 年 4 月 20 日
Compute start and stop indices for NaN segments in height variable (column vector).
nanStartIdx = find(diff(isnan([0;height;0]))==1);
nanStopIdx = find(diff(isnan([0;height;0]))==-1);
Show the results.
% Show index of NaN values
ax = cla();
plot(isnan(height), '-k', 'LineWidth', 2)
ylim([-.2, 1.5])
xlabel('index')
ylabel('is NaN')
set(ax, 'YTick', [0,1], 'YTickLabel', {'False', 'True'})
hold on
arrayfun(@(start)xline(start, 'b-','Start'), nanStartIdx)
arrayfun(@(stop)xline(stop, 'c-','Stop'), nanStopIdx)
  2 件のコメント
Binu
Binu 2020 年 4 月 21 日
Thanks Adam. Much appreciated
Maria Battle
Maria Battle 2024 年 2 月 23 日
編集済み: Maria Battle 2024 年 2 月 23 日
Good solution! If you wanted Stop to be aligned with the last NaN value of each gap, try
nanStopIdx = find(diff(isnan([0;height;0]))==-1)-1;

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by