MATLAB: Cleaning Matrix

MATLABmatrix replacing values

Hi,
I have the following matrix called Data(size=n*1) (actually tenth of them) that I need to clean. The idea is simple:
If there is a number then no change
If there is not a number then, I replace by:
the previous number, if there is one.
the next number, if there is no previous number.
Example Data matrix
Data=
[]
[]
20
[]
25
[]
100
Result=
20
20
20
20
25
25
100
Your help would be much appreiated.
Thanks
Xavier

Best Answer

Data={[]
[]
20
[]
25
[]
100};
t = ~cellfun(@isempty,Data)
Data(1) = Data(find(t,1,'first'))
t = [true;t(2:end)]
idx = cumsum(t)
D1 = Data(t)
out = D1(idx)