Find the begining and ending on nan sequence and store

조회 수: 1 (최근 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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by