There's no such thing as element 0, row 0, or column 0 in a matrix in MATLAB.
If you replace your 999999 values with NaN you could use fillmissing with the 'movmean' method, at least assuming you intend "previous and later data" to refer to the previous and next data point in a particular row or column not along a diagonal as your code currently computes. As an example, make some sample data.
x = randi(10, 1, 10)
Change some of the values in x into NaN (missing values.)
Take the moving mean with a window of 1 element before and after the current element.
result = fillmissing(x, 'movmean', [1 1])
Element 4 of result is the average of elements 3 and 5 of x since element 4 of x is missing.
Element 7 of result is the average of elements 6 and 8 of x since element 7 of x is missing.
The remaining elements in result are the same as the corresponding (non-missing) elements of x.