Create new matrix by date/time

조회 수: 7 (최근 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 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