How to find index of continous non-NaN values?

50 ビュー (過去 30 日間)
Dolly More
Dolly More 2022 年 1 月 24 日
コメント済み: Walter Roberson 2022 年 1 月 25 日
Hi, I want to find index of continuous non-NaN values in a row of a matrix. In the attached file, maximum non-NaN data value block is 600 which is at the end of the array. I want to find start and end of this block of max continuous non-NaN data values.
I used following code from this link,
D = diff([false,~isnan(Sal),false]);
L = find(D<0)-find(D>0) ;
I need help to get the start and end index of such block from an array with maximum data values if such block of continuous value is in the middle of an array.
My goal is to use this block for spectral analysis. Hence, I need continuous data values. Also, the data is discontinuous sometimes, so I am trying to just use the bigger block of continuous values.
Please forgive my errors in framing the problem.
Thank you.

採用された回答

Walter Roberson
Walter Roberson 2022 年 1 月 24 日
mask = ~isnan(Sal(:).'); %row vector needed
starts = strfind([false mask], [false true]);
stops = strfind([mask false], [true false]);
Now Sal(starts(K):stops(K)) is a block of consecutive non-nan values.
  4 件のコメント
Dolly More
Dolly More 2022 年 1 月 25 日
Okay. I used following code to pick one pair of index.
Df = stops - starts;
mx= find(Df==max(Df));
Sal(starts(mx)+1:stops(mx))
Walter Roberson
Walter Roberson 2022 年 1 月 25 日
that will not work if there are two blocks each maximum length, whereas the max() call I showed would work in that case.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by