I have this information
Mat=[1 2 3 5;6 7 -9999 9;10 11 12 13;14 -9999 16 17;18 19 -9999 -9999]
Mat(Mat<0)=NaN
Mat =
1 2 3 5
6 7 NaN 9
10 11 12 13
14 NaN 16 17
18 19 NaN NaN
How could you replace only the NaN with the average value of the values on your left and right
Mat =
1 2 3 5
6 7 8 9
10 11 12 13
14 15 16 17
18 19 NaN NaN
What complicates me is that it is important the location of the NaNs and their respective adjacent values, for example for the NaN (2,3), it has to be replaced by 7 and 9