From: Stephanie on
Hi there,

I have a vector where the first few values at the beginning and end are NaN, and I would like to replace these values with the nearest "real" value.

For example;

NaN
NaN
NaN
3
6
10
30
100
NaN
NaN

Would become;

3
3
3
3
6
10
30
100
100
100

Also, could this be applied to a matrix with the same problem? E.g. the first few rows and the last few rows of a matrix all contain NaN to be filled with nearest non-NaN value?

Many thanks,
Steph