Create new matrix by date/time

2 次查看(过去 30 天)
I have an excel sheet that contains a column of dates and a column of times. Also, each day is designated by its own header (I have attached the sheet to this question). I want to be able to extract each day of data and put it into its own matrix (without any of the headers). Any recommendations on the best way to accomplish this?
  1 个评论
Samantha Wallace
Samantha Wallace 2018-5-29
Also, I need to code to work for different excel sheets with different sets of dates/times. So it needs to recognize different dates but not specific ones. Needs to work on a general basis.

请先登录,再进行评论。

回答(2 个)

Nikhil Negi
Nikhil Negi 2018-5-31
Hello Samantha,
If you didn't have any header in your file you could have directly used readtable
but since you have headers for each date, what you can do is read the xls file as table and search for the string 'Date' by lopping over 1st column of the table and save its index and then search for the string 'Date' again and save its index and extract the data from between these two indices. you can do that over and over and get the data between different dates.

Peter Perkins
Peter Perkins 2018-6-4
The answer depends on what version of MATLAB you have. In recent versions, if you use readtable, that date column in the spreadsheet will be read in as a datetime variable in the table. The time column will propbably be read in as text.
To convert to durations, use this utility:
and then (assuming you want the date and time combined) just add the durations to the datetimes. Something like
t = readtable('Dat3eTimeData.xls');
t.Time = text2duration(t.Time);
t.DateTime = t.Date + t.Time

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by