Find the begining and ending on nan sequence and store
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Tiago Dias
el 24 de Sept. de 2018
Comentada: Tiago Dias
el 24 de Sept. de 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.
0 comentarios
Respuesta aceptada
Stephen23
el 24 de Sept. de 2018
Editada: Stephen23
el 24 de Sept. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!