Problem 58339. Remove runs of at least n consecutive NaNs
This problem is inspired by Dyuman Joshi's problem 58329. Given a row vector x and a natural number n, remove all runs of at least n consecutive NaNs from x, leaving all shorter runs as well as all non-NaN elements intact.
For instance, given
the results would be as follows:
with no changes in output for even higher n (since x only contains runs of NaNs up to length four).
To make this challenging, provide a vectorized solution: no loops, no arrayfun (in fact, no fun at all, though you're still allowed to have fun), and no recursion. Regular expressions are also outlawed (I don't think that this is a problem that is naturally solved using regular expressions, so I don't feel too bad about doing so).
Solution CommentsShow comments
Problem Recent Solvers3