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

1 visualización (últimos 30 días)
BN
BN el 11 de Feb. de 2020
Comentada: BN el 11 de Feb. de 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 comentarios
Luna
Luna el 11 de Feb. de 2020
If the NaN percentage smaller than 15%, do you want to fill entire column with NaNs ?
BN
BN el 11 de Feb. de 2020
Editada: BN el 11 de Feb. de 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

Iniciar sesión para comentar.

Respuesta aceptada

Robert U
Robert U el 11 de Feb. de 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

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by