What is the simplest way to extract lengths of NaN sequences from a vector?
Show older comments
What is the simplest way to extract lengths of NaN sequences from a vector? Plus the indices of their locations!
Accepted Answer
More Answers (1)
Bruno Luong
on 2 Oct 2018
Edited: Bruno Luong
on 2 Oct 2018
% a is the input vector
b = isnan(a);
counts = sum(b);
positions = find(b);
3 Comments
Stephen23
on 2 Oct 2018
+1 isnan is correct.
Mr M.
on 2 Oct 2018
Bruno Luong
on 2 Oct 2018
Edited: Bruno Luong
on 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
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!