create a time table from specific time date format
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello!
I have a historical data that I need to import and create a timetable from. the date and time are not in the standard format that I import and convert. I would appreciate if you can help me how can I do so (data attached)
Date,Time,Open,High,Low,Close,Volume
20010102,230000,64.30,64.31,64.27,64.28,48
20010102,231500,64.28,64.29,64.27,64.28,52
20010102,233000,64.28,64.28,64.25,64.26,40
20010102,234500,64.27,64.35,64.27,64.35,44
20010103,000000,64.30,64.44,64.30,64.44,52
Thanks.
0 Kommentare
Akzeptierte Antwort
jonas
am 15 Aug. 2018
Bearbeitet: jonas
am 15 Aug. 2018
The format is not an issue but there are several ways to import. Here is one:
opts = detectImportOptions('data.txt');
opts = setvartype(opts, 'char');
tbl = readtable('data.txt',opts);
C=strcat(tbl.Date, {' '}, tbl.Time)
datetime(C,'inputformat','yyyyMMdd HHmmSS')
You can also experiment a bit more with the detectImportOptions to avoid post-processing
opts = detectImportOptions('data.txt');
opts = setvartype(opts,'Date','datetime');
opts = setvartype(opts,'Time','datetime');
opts = setvaropts(opts,'Date','InputFormat','yyyyMMdd')
opts = setvaropts(opts,'Time','InputFormat','HHmmss')
T = readtable('data.txt',opts)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!