How to import Date and time in two different cells?

1 vue (au cours des 30 derniers jours)
SEPIDEH
SEPIDEH le 19 Oct 2015
Hi, I want to import the excel file that I attached here in Matlab, which the first column is time, and the second column is hourly data based on each hour [time]. How is it possible to import them in the correct way to matlab? Attached my excel file.
Thanks in advance for help Sepideh

Réponses (1)

Peter Perkins
Peter Perkins le 19 Oct 2015
Using readtable in R2015a, the dates come in as strings, the times as numbers:
>> t = readtable('test.xlsx');
>> t(1:5,:)
ans =
Date Time F1 F2 F3 F5 F7 F11 F14 H10
____________ ________ ______ ______ ______ ______ ______ ______ ______ ______
'2006-10-19' 0 76.579 76.984 77.291 76.902 76.822 76.969 77.525 76.964
'2006-10-19' 0.041667 76.573 76.969 77.281 76.894 76.817 76.962 77.523 76.954
'2006-10-19' 0.083333 76.564 76.958 77.272 76.885 76.808 76.952 77.514 76.943
'2006-10-19' 0.125 76.554 76.941 77.265 76.873 76.797 76.94 77.503 76.932
'2006-10-19' 0.16667 76.559 76.932 77.246 76.861 76.787 76.929 77.509 76.923
So convert the strings to datetime, and add the day fractions:
>> t.DateTime = datetime(t.Date) + days(t.Time);
>> t(1:5,:)
ans =
Date Time F1 F2 F3 F5 F7 F11 F14 H10 DateTime
____________ ________ ______ ______ ______ ______ ______ ______ ______ ______ ____________________
'2006-10-19' 0 76.579 76.984 77.291 76.902 76.822 76.969 77.525 76.964 19-Oct-2006 00:00:00
'2006-10-19' 0.041667 76.573 76.969 77.281 76.894 76.817 76.962 77.523 76.954 19-Oct-2006 01:00:00
'2006-10-19' 0.083333 76.564 76.958 77.272 76.885 76.808 76.952 77.514 76.943 19-Oct-2006 02:00:00
'2006-10-19' 0.125 76.554 76.941 77.265 76.873 76.797 76.94 77.503 76.932 19-Oct-2006 03:00:00
'2006-10-19' 0.16667 76.559 76.932 77.246 76.861 76.787 76.929 77.509 76.923 19-Oct-2006 04:00:00
Hope this helps.

Catégories

En savoir plus sur Data Import from MATLAB 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