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

1 vue (au cours des 30 derniers jours)
BN
BN le 11 Fév 2020
Commenté : BN le 11 Fév 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 commentaires
Luna
Luna le 11 Fév 2020
If the NaN percentage smaller than 15%, do you want to fill entire column with NaNs ?
BN
BN le 11 Fév 2020
Modifié(e) : BN le 11 Fév 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

Connectez-vous pour commenter.

Réponse acceptée

Robert U
Robert U le 11 Fév 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

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by