fillmissing if the amount of NaN smaller than 15% in all table.

1 次查看(过去 30 天)
Hello,
I have a cell named NewC2LatLon. This cell including 1200 tables. I want to check the “precip” column of each table and fill NaN in this column if the number of all NaN in this column smaller than 15% of all data in this column in the same table. But I don't want to fill any NaN if the number of amount of NaN in a column bigger than 15%.
I tried to do what I want using
nanPercent = cell2mat(cellfun(@(x)mean(isnan(x{:,col}),5),NewC2LatLon,'UniformOutput',false)');
NaN_i = 0;
for y = 1:NewC2LatLon.precip
if(NewC2LatLon.precip < 15)
NaN = NaN_i + 1;
end
if NaN_i<=15
NewC2LatLon = cellfun(@(x)fillmissing(NewC2LatLon, 'linear', 'DataVariables', {'precip'}));
But it's wrong and I don't know what should I do. I attached my cell.
Thank you
  2 个评论
Luna
Luna 2020-2-11
If the NaN percentage smaller than 15%, do you want to fill entire column with NaNs ?
BN
BN 2020-2-11
编辑:BN 2020-2-11
Hello Luna, No, if the NaN percentage is smaller than 15% I want to fill NaN's in the column using fillmissing function. If bigger than 15% I would do nothing.
?Thank You

请先登录,再进行评论。

采纳的回答

Robert U
Robert U 2020-2-11
Hi Behzad Navidi,
please test whether these two lines fulfill your requirements:
nanPercent = cellfun(@(cIn) sum(isnan(cIn.precip))/size(cIn.precip,1),NewC2LatLon);
NewC2LatLon(nanPercent<0.15) = cellfun(@(cIn) fillmissing(cIn, 'linear', 'DataVariables', {'precip'}),NewC2LatLon(nanPercent<0.15),'UniformOutput',false);
Kind regards,
Robert

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by