What is the simplest way to extract lengths of NaN sequences from a vector?
Mostra commenti meno recenti
What is the simplest way to extract lengths of NaN sequences from a vector? Plus the indices of their locations!
Risposta accettata
Più risposte (1)
Bruno Luong
il 2 Ott 2018
Modificato: Bruno Luong
il 2 Ott 2018
% a is the input vector
b = isnan(a);
counts = sum(b);
positions = find(b);
3 Commenti
Stephen23
il 2 Ott 2018
+1 isnan is correct.
Mr M.
il 2 Ott 2018
Bruno Luong
il 2 Ott 2018
Modificato: Bruno Luong
il 2 Ott 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
Categorie
Scopri di più su NaNs in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!