What is the simplest way to extract lengths of NaN sequences from a vector?
Afficher commentaires plus anciens
What is the simplest way to extract lengths of NaN sequences from a vector? Plus the indices of their locations!
Réponse acceptée
Plus de réponses (1)
Bruno Luong
le 2 Oct 2018
Modifié(e) : Bruno Luong
le 2 Oct 2018
% a is the input vector
b = isnan(a);
counts = sum(b);
positions = find(b);
3 commentaires
Stephen23
le 2 Oct 2018
+1 isnan is correct.
Mr M.
le 2 Oct 2018
Bruno Luong
le 2 Oct 2018
Modifié(e) : Bruno Luong
le 2 Oct 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
Catégories
En savoir plus sur NaNs dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!