- What are the two formats?
- Since a datenum is just a double, it's possible to have rounding issues using ismember in comparison of date numbers created by different means...
Reduce rows if dates don't match
1 次查看(过去 30 天)
显示 更早的评论
I want to reduce the table MSCI by the rows which have a different date than the table AdjDate. Thus, I want to include only the dates whih are inluded in both tables As the dates are in different formats, I first converted the dates to numerical dates and tried to reduce them using the following code but it didnt give me the output i wanted to have
DateNum = datenum(AdjDate.TimeWindow)
DateNUMM = datenum(MSCI.Date)
DateTableM = array2table(DateNUMM)
AdjDateMSCI = [MSCI DateTableM];
AdjDateMSCI(ismember(AdjDateMSCI.Date,AdjDate.TimeWindow),:)=[];
4 个评论
Guillaume
2019-6-1
If I use datetitime it also doesnt produce the output i would like to have
Most likely, you're doing something wrong. We can't tell you what if you don't give more details such as code and example data.
In particular, datetime does not care one bit about the actual formatting of the date to perform date comparison:
>> d1 = datetime('01.06.2019', 'Format', 'dd.MM.yyyy')
d1 =
datetime
01.06.2019
>> d2 = datetime('2019-06-01', 'Format', 'yyyy-MM-dd')
d2 =
datetime
2019-06-01
>> d1 == d2
ans =
logical
1
And as dpb said, if you have two tables for which you want to compute the intersection based on time, it can be done in just one line with synchronize if you convert the tables to timetables (not time series!).
dpb
2019-6-1
Thanks, Guillaume -- I did mean the time table object NOT the time series! I have yet to find a use for it that it isn't more in the way than help...I'll fixup the note to match intent.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!