Replace NaN with median per column
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I have a matrix where I have NaN values in a few columns.
I would like to fill the NaN values with the median value of that column. How do I do that?
0 comentarios
Respuestas (4)
Wan Ji
el 10 de Ag. de 2021
It is convenient to use fillmissing function to get what you want
matOut = fillmissing(matrixIn, 'linear', 'EndValues','nearest')
4 comentarios
Yazan
el 10 de Ag. de 2021
This does linear interpolation of neighboring non-nan values. It does not replace nan values with the median.
Yazan
el 10 de Ag. de 2021
clc, clear
x1 = randn(5, 5);
x1(randi(numel(x1), 1, 5)) = nan;
x2 = fillmissing(x1, 'movmedian', size(x1,1)*2, 1);
display(x1)
display(x2)
0 comentarios
Ver también
Categorías
Más información sobre NaNs 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!