# Filling in missing points

10 visualizaciones (últimos 30 días)
Feng Xu el 30 de Mzo. de 2020
Editada: Andrei Bobrov el 30 de Mzo. de 2020
Hi, all. I have a quesion about filling missing points.
I need to fill in the missing points according to these rules:
- If there’s only one missing point, with valid data present on both sides of that point, the missing point shall be assigned the average of the two known data-points either side of it.
- If there are multiple, consecutive data-points missing, the closest known data point will be assigned to those missing values.
I have finished the first rule, but I don't know how to deal with second rule.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Andrei Bobrov el 30 de Mzo. de 2020
Editada: Andrei Bobrov el 30 de Mzo. de 2020
In R2016b:
TT = table2timetable(T);
TTout = fillmissing(TT,'linear');
TT = table2timetable(T);
A = varfun(@f1,TT);
function out = f1(x)
b1 = fillmissing(x,'linear');
b2 = fillmissing(x,'nearest');
d = [0;diff(bwdist(~isnan(x)),2);0]==-2;
out = b2;
out(d) = b1(d);
end
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Feng Xu el 30 de Mzo. de 2020
Thanks for your answer, but the second rule says:
If there are multiple, consecutive data-points missing, the closest known data point will be assigned to those missing values.
I would like to know how to deal with this part of the problem. For example, if：
30
NaN
NaN
27
therefore, the first NaN should be 30, the second Nan should be 27.
On the other hands, if:
30
NaN
NaN
NaN
27
therefore, the first NaN should be 30, the third NaN should be 27 and the second NaN should be the average of 30 and 27 which is 28.5.

Iniciar sesión para comentar.

### Categorías

Más información sobre Spreadsheets en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by