combine 2 timetables with different variables into 1 timetable?

7 vues (au cours des 30 derniers jours)
Angelavtc
Angelavtc le 19 Mai 2022
Commenté : dpb le 21 Mai 2022
I have two timetables with different "time format"
I want to merge timetable 1 with timetable 2 to get timetable 3 as the following image:
Using join I get the following error: "The key variable for B must contain all values in the key variable for A."
which I guess it is because the timetable have different time format, but event if I change this, the error is still there.
Any Idea how to solve this?
Thank you in advance!
  4 commentaires
Dyuman Joshi
Dyuman Joshi le 20 Mai 2022
Can you attach your data here?
Angelavtc
Angelavtc le 20 Mai 2022
@Dyuman Joshi For example this
d = string({'2017-01-01 11:00','2017-01-01 12:00'});
Date= datetime(d,'InputFormat','yyyy-MM-dd HH:mm')';
Price= [40 35]';
T1= table(Date, Price)
TT1= table2timetable(T1)
d1 = string({'2017-01-01','2017-01-02'});
Date= datetime(d1,'InputFormat','yyyy-MM-dd')';
Volume= [400 350]';
T2= table(Date, Volume)
TT2= table2timetable(T2)
TT1.Date = datetime(TT1.Date,'Format','yyyy-MM-dd');
TT3 = outerjoin(TT1,TT2,'MergeKeys',true);
So the result is not at all what I would like to have. I would like to end up with a timetable like this:
d2 = string({'2017-01-01 11:00','2017-01-01 12:00'});
Date= datetime(d,'InputFormat','yyyy-MM-dd HH:mm')';
Price= [40 35]';
Volume= [400 400]';
T3= table(Date, Price, Volume)
TT3= table2timetable(T3)
Thank you!

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 21 Mai 2022
ttC=synchronize(ttA,ttB); % catenate the two horizontally at matching times
ttC=ttC(isfinite(ttC.Price),:); % remove those w/ no Price data
ttC=retime(ttC,'hourly',"previous"); % fill in missing volume data with first value of period
  2 commentaires
Angelavtc
Angelavtc le 21 Mai 2022
@dpb this works well! Thank you!
dpb
dpb le 21 Mai 2022
Glad to help...just went thru same exercise in a more exotic form last week, so had in hip pocket... :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Chart Technical Indicators dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by