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

1 Ansicht (letzte 30 Tage)
BN
BN am 11 Feb. 2020
Kommentiert: BN am 11 Feb. 2020
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 Kommentare
Luna
Luna am 11 Feb. 2020
If the NaN percentage smaller than 15%, do you want to fill entire column with NaNs ?
BN
BN am 11 Feb. 2020
Bearbeitet: BN am 11 Feb. 2020
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Robert U
Robert U am 11 Feb. 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by