How to import Date and time in two different cells?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Peter Perkins
2015-10-19
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!