MATLAB: Replacing NaN with the average of previous and next cell value

replacing nan

I have a data set like,
time 1 2 3 4 5 6 7 8
exp1 45 67 78 NaN 80 81 82 83
These are two separate column with time and exp1 as header. how do I replace the NaN with the average of previous cell value and the next. Like in the above example, NaN should be replaced by 79 ((78+80)/2 )
Thanks in advance

Best Answer

This sounds like a use for fillmissing with linear option:
>> exp1 = [45 67 78 NaN 80 81 82 83];
>> fillmissing(exp1,'linear')
ans =
45 67 78 79 80 81 82 83