Inserting missing dates and values
15 次查看(过去 30 天)
显示 更早的评论
I have two column matrix representing a time series data with daily interval. But I have few missing data so some of the dates are not shown in the matrix. But I need to insert all possible dates in the data series where the missing values should be equal to the previous day’s value. Can I do it in Matlab? For example the matrix looks like x=[Jan1 10; Jan2 12; Jan4 16] but it should be x=[Jan1 10; Jan2 12; Jan3 12; Jan4 16]. It looks very simple in this example but I have millions of data so it is not possible to correct manually. Anyone can help please?
6 个评论
Image Analyst
2020-5-18
编辑:Image Analyst
2020-5-18
You said you have the same problem as Mohammad. The two answers below offered a solution so there is a chance they may work for you also. If you already read them and you say it does not apply to your problem, then evidently you do not have the same problem (kind of a contradiction). So we're now not sure if you have the same problem or not. Anyway...
If you have a different problem, read this link first, and then post your own new question with your own data attached.
回答(2 个)
Steven Lord
2017-11-10
编辑:Steven Lord
2017-11-10
If you're using a release of MATLAB that includes timetable, create a timetable with your data then use retime on that timetable.
% Create some time and data variables
>> t = datetime(2017, 1, [1; 2; 4]);
>> x = [10; 12; 16];
% Assemble the timetable and display it
>> tt = timetable(t, x)
tt =
3×1 timetable
t x
___________ __
01-Jan-2017 10
02-Jan-2017 12
04-Jan-2017 16
% Generate daily data in your timetable, filling in new rows with
% the previous day's data
>> tt2 = retime(tt, 'daily', 'previous')
tt2 =
4×1 timetable
t x
___________ __
01-Jan-2017 10
02-Jan-2017 12
03-Jan-2017 12
04-Jan-2017 16
% Generate daily data in your timetable, but fill new rows with missing data
% For a double variable, 'missing' means NaN
>> tt3 = retime(tt, 'daily', 'fillwithmissing')
tt3 =
4×1 timetable
t x
___________ ___
01-Jan-2017 10
02-Jan-2017 12
03-Jan-2017 NaN
04-Jan-2017 16
0 个评论
Image Analyst
2014-12-23
I don't know what type of data x is, but convert them to a number with sprintf() and datenum(). Then use interp1() to fill in the missing dates.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!