フィルターのクリア

Create new matrix by date/time

5 ビュー (過去 30 日間)
Samantha Wallace
Samantha Wallace 2018 年 5 月 29 日
回答済み: Peter Perkins 2018 年 6 月 4 日
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 Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by