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

조회 수: 1 (최근 30일)
BN
BN 2020년 2월 11일
댓글: BN 2020년 2월 11일
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