What is the simplest way to extract lengths of NaN sequences from a vector?
Ältere Kommentare anzeigen
What is the simplest way to extract lengths of NaN sequences from a vector? Plus the indices of their locations!
Akzeptierte Antwort
Weitere Antworten (1)
Bruno Luong
am 2 Okt. 2018
Bearbeitet: Bruno Luong
am 2 Okt. 2018
% a is the input vector
b = isnan(a);
counts = sum(b);
positions = find(b);
3 Kommentare
Stephen23
am 2 Okt. 2018
+1 isnan is correct.
Mr M.
am 2 Okt. 2018
Bruno Luong
am 2 Okt. 2018
Bearbeitet: Bruno Luong
am 2 Okt. 2018
Sorry, for sequence:
b = isnan(a(:)');
d = diff([0 b 0]);
i1 = find(d==1);
i9 = find(d==-1)-1;
if ~isempty(lgt)
fprintf('nan from (%d,%d)\n', [i1;i9]);
end
Kategorien
Mehr zu NaNs finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!