Filter löschen
Filter löschen

create a time table from specific time date format

5 Ansichten (letzte 30 Tage)
Sonima
Sonima am 15 Aug. 2018
Bearbeitet: Sonima am 15 Aug. 2019
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.

Akzeptierte Antwort

jonas
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)

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by