发布时间:2024-07-02 18:01
A = [3 NaN 7
NaN 999.99 1];
id = [NaN 999.99];
TF = ismissing(A,id);
结果:
TF = [ 0 1 0
1 1 0 ]
A = [0 1 -99
1 -99 3];
B = standardizeMissing(A,-99);
结果:
B = [0 1 NaN
1 NaN 3]
3.1 填充方法
% \'previous\':上一个非缺失值
% \'next\':下一个非缺失值
% \'nearest:距离最近的非缺失值
% \'linear\':相邻非缺失值的线性插值
% 替换包含缺失值的列
A = [1 2
NaN 3
4 NaN];
F = fillmissing(A,\'previous\',1);
结果:
F = [1 2
1 3
4 3]
3.2 移动方法
% \'movmean\':窗口长度为 window 的移动均值
% \'movmedian\':窗口长度为 window 的移动中位数
% 替换包含缺失值的列
A = [1 2
NaN 3
4 NaN];
F = fillmissing(A,\'movmean\',4,1);
结果:
F = [1.0000 2.0000
2.5000 3.0000
4.0000 2.5000]
% 移除包含缺失值的行
A=[NaN 1 2 3
3 4 5 6];
R = rmmissing(A,1);
结果:
R = [3 4 5 6]
A = [1 2 300 1
1 300 1 2];
% 寻找每行的离群值,参数有\'mean\'、\'median\'|\'movmean\'、\'movmedian\'
TF = isoutlier(A,\'median\',2);
TF = isoutlier(A,\'movmedian\',4,2)
结果:
TF = [0 0 1 0
0 1 0 0]
% \'previous\':上一个非缺失值
% \'next\':下一个非缺失值
% \'nearest:距离最近的非缺失值
% \'linear\':相邻非缺失值的线性插值
% \'movmean\':窗口长度为 window 的移动均值
% \'movmedian\':窗口长度为 window 的移动中位数
% 替换包含离群值的列
A = [1 2
300 3
4 300];
B = filloutliers(A,\'linear\',\'movmedian\',4,1)
结果:
B = [1.0000 2.0000
2.5000 3.0000
4.0000 4.0000]
% 删除包含离群值的行
A = magic(5);
A(4,4) = 500;
A(5,5) = 500;
B = rmoutliers(A,\'median\',1)
B = rmoutliers(A,\'movmedian\',4,1)