Interpolate Nan values in timetable

6 次查看(过去 30 天)
youma
youma 2023-4-30
回答: Matt J 2023-4-30
Data from the meteo with every day from 01/01/2022 to 31/12/2022 within 10mn of interval. What I'm trying to is to interpolate my missing values from meteo_full_data but based on the mean of previous {20,40,60 } days before and after the missing period. But I can't figure out how, this is what I got so far :
% start and end dates for the missing 20 days
start_date = datetime(2022, 6, 19, 21, 50, 0);
end_date = datetime(2022, 7, 8, 15, 50, 0);
% Calculate the means for the before and after periods
mean_before_60 = mean(data_before_60{:,:}, 'omitnan');
mean_before_40 = mean(data_before_40{:,:}, 'omitnan');
mean_before_20 = mean(data_before_20{:,:}, 'omitnan');
mean_after_20 = mean(data_after_20{:,:}, 'omitnan');
mean_after_40 = mean(data_after_40{:,:}, 'omitnan');
mean_after_60 = mean(data_after_60{:,:}, 'omitnan');
cols_to_interp = {'AR_Hum_', 'AR_Temp_C', 'GlobalRadiation5DegressKWh', 'GlobalRadiation45DegressKWh'};
mean_before = [mean_before_60; mean_before_40; mean_before_20];
mean_after = [mean_after_20; mean_after_40; mean_after_60];
mean_table= [mean_before;mean_after];
%mean_table = mean(mean_table, 'all')
data_to_interp = meteo_full_data(meteo_full_data.TimeStamp >= start_date & meteo_full_data.TimeStamp <= end_date, cols_to_interp)
And I tried these two methods, no good :
inter_data = fillmissing(data_to_interp, 'constant', mean_table, 'DataVariables', cols_to_interp);
%inter_data = fillmissing(data_to_interp,"linear","DataVariables",cols_to_interp)
and this one
%missing_rows = any(ismissing(meteo_full_data(:, cols_to_interp)), 2);
% Replace the missing values with the mean values
meteo_full_data(missing_rows, cols_to_interp) = num2cell(repmat(mean_table, sum(missing_rows), length(cols_to_interp)))

回答(1 个)

Matt J
Matt J 2023-4-30
You could use movmean, like in this example,

类别

Help CenterFile Exchange 中查找有关 Interpolating Gridded Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by