How to remove NaNs from an array between points

1 view (last 30 days)
I have an array consisting of real numbers and NaNs. I'd like to identify the first row where there is a real number, then extract data from that point to when the next NaN occurs. If you see the attached example, I'd like the results to be example(17:43).
Thanks to the community for the help and let me know if I can cleary anything up!
  1 Comment
BuMatlab
BuMatlab on 9 Mar 2021
Sorry - one more item: I'd like the Nans before the first real number row to remain intact - this would mean the results are example(1:43)

Sign in to comment.

Accepted Answer

KSSV
KSSV on 9 Mar 2021
Read about isnan.
idx = isnan(example);
idr = diff(find([1;diff(idx);1]));
D = mat2cell(example,idr(:),size(example,2));
celldisp(D)
  2 Comments
BuMatlab
BuMatlab on 9 Mar 2021
Thanks, KSSV. It appears the length(D) ~= example(17:43) - any ideas?

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!