Effacer les filtres
Effacer les filtres

Find the begining and ending on nan sequence and store

2 vues (au cours des 30 derniers jours)
Tiago Dias
Tiago Dias le 24 Sep 2018
Commenté : Tiago Dias le 24 Sep 2018
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.

Réponse acceptée

Stephen23
Stephen23 le 24 Sep 2018
Modifié(e) : Stephen23 le 24 Sep 2018
>> 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

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by