Spread monthly data into days
8 次查看(过去 30 天)
显示 更早的评论
Hello,
I am new to Matlab and I am trying to spread monthly data into a table that is indexed daily. For example:
Date Data
01/1982 0.15
02/1982 -0.02
03/1982 -0.05
What I would like to achieve...
Date Data
1/1/1982 0.15
1/2/1982 0.15
1/3/1982 0.15
1/4/1982 0.15
....
1/31/1982 0.15
2/1/1982 -0.02
2/2/1982 -0.02
2/3/1982 -0.02
2/4/1982 -0.02
I other words, I am trying to convert a table with 240 rows (20 years in months) to one with 7300 rows (20 years in days).
Is this easily doable in matlab? Greatly appreciate any advice.
0 个评论
采纳的回答
Kelly Kearney
2021-9-25
One way to do the expansion... convert your monthly dates to the first of each month, then use dateshift to check which month each of your days match:
% Some placeholder data... you'll have to read your tables as appropriate
tmon = datetime(1982, 1:3, 1);
ymon = [0.15 -0.02 -0.05];
tday = datetime(1982,1,1) + days(0:89);
% Match up days to months
[~,loc] = ismember(dateshift(tday, 'start', 'month'), tmon);
yday = ymon(loc);
3 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!