Borrar filtros
Borrar filtros

create a time table from specific time date format

5 visualizaciones (últimos 30 días)
Sonima
Sonima el 15 de Ag. de 2018
Editada: Sonima el 15 de Ag. de 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.

Respuesta aceptada

jonas
jonas el 15 de Ag. de 2018
Editada: jonas el 15 de Ag. de 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)

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by