Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 694. Remove NaNs and numbers adjacent to NaNs

Created by Richard Zapor

The aim is to remove the elements before and after NaN occurrences inside a vector.

For example:

 x = [6 10 5 8 9 NaN 23 10 7 3 21 43 NaN 4 6 7 8]

The output y will be:

 y = [6 10 5 8 10 7 3 21 6 7 8]

If NaNs occur at the beginning or end then first two or last two values are removed.

 x=[NaN 1 2 3]  yields [2 3]

NaN values will exist in every case. No case is an empty set.

Problem Group

Solution Statistics

40 correct solutions 23 incorrect solutions
Last solution submitted on Jun 10, 2014