Replace NaN with median per column
7 次查看(过去 30 天)
显示 更早的评论
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/707997/image.png)
0 个评论
回答(4 个)
Yazan
2021-8-10
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Preprocessing Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!