フィルターのクリア

Find the begining and ending on nan sequence and store

2 ビュー (過去 30 日間)
Tiago Dias
Tiago Dias 2018 年 9 月 24 日
コメント済み: Tiago Dias 2018 年 9 月 24 日
Hi,
A = [7 9;NaN 9; NaN NaN; 4 NaN; 6 7;7 9;NaN 9; NaN NaN; 4 NaN; 6 7]
In both columns, i got 2 sequences of NaN's of length 2.
For each column i want to store the begining index and ending index of each sequence, and the length of it.
To something like:
result = cell(#number of NaN sequences of A), Size(A,2))
result = (2,3,2) (3,4,2)
(7,8,2) (8,9,2)
And "result" could be a cell, where the column of "result" is all calculations related to column 1 of A.
hope it was clear enough,
Thanks
TLDR: I can only find the index of NaN values in my matrix A, i need a way to find the begining and end of each sequence and their length per column.

採用された回答

Stephen23
Stephen23 2018 年 9 月 24 日
編集済み: Stephen23 2018 年 9 月 24 日
>> A = [7,9;NaN,9;NaN,NaN;4,NaN;6,7;7,9;NaN,9;NaN,NaN;4,NaN;6,7]
A =
7 9
NaN 9
NaN NaN
4 NaN
6 7
7 9
NaN 9
NaN NaN
4 NaN
6 7
>> T = false(1,size(A,2));
>> D = diff([T;isnan(A);T],1,1);
>> [Rb,Cb] = find(D>0);
>> [Re,Ce] = find(D<0);
>> [Rb,Re-1,Re-Rb,Cb] % [start,end,length,column]
ans =
2 3 2 1
7 8 2 1
3 4 2 2
8 9 2 2
  1 件のコメント
Tiago Dias
Tiago Dias 2018 年 9 月 24 日
Thanks, works like a charm :)

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

その他の回答 (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