create a time table from specific time date format
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
jonas
2018-8-15
编辑:jonas
2018-8-15
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!