Reduce rows if dates don't match

1 visualización (últimos 30 días)
AU
AU el 1 de Jun. de 2019
Editada: dpb el 1 de Jun. de 2019
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 comentarios
Guillaume
Guillaume el 1 de Jun. de 2019
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
dpb el 1 de Jun. de 2019
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Variables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by