How to Match Different Formatted Date Strings from Multiple Tables
1 次查看(过去 30 天)
显示 更早的评论
Hello, I need help with date strings.
I have 2 tables, Table 1 has timeseries with this time format: i.e. 2000-06-02_00:00:00
And Table 2 has this time format: i.e. 02.06.2000 (day/month/year)
I have to create a loop starting from "2000-06-02" with 1 day increments for next 5 days, then find the matching row number on Table 2's date column, then parse the needed data from the corresponding row number on another column, but I am stuck at finding the correct functions for the task. I wrote the following part of my code but got a "DATENUM Failed, caused by Cannot parse date' error.
On code "time" is time column of Table 1, and "obstime" is of Table 2.
Any help is much appreciated.
Thanks in advance.
P=24;
D=5;
for N=1:D
if N == 1
Date{N}=datenum(datestr(datenum(time(1,1)),'dd.mm.yyyy'));
y=find(obstime,Date{N});
Obs_out(N)=PtData(y);
Day_out(N,1)=mean(A(1:23));
elseif N > 1
d=Date{N-1};
dn=datenum(datestr(d+1));
y=find(obstime,dn);
Obs_out(N)=PtData(y);
S=P+23;
Day_out(N,1)=mean(A(P:S));
P=S+1;
2 个评论
Thomas
2012-9-26
Why are you going from datenum-datestr-datenum
b1={'02.06.2000'}
datenum(b1,'DD.MM.YYYY')
ans =
730487.00
Works just fine..
回答(0 个)
另请参阅
类别
在 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!