Azzera filtri
Azzera filtri

Create new matrix by date/time

5 visualizzazioni (ultimi 30 giorni)
Samantha Wallace
Samantha Wallace il 29 Mag 2018
Risposto: Peter Perkins il 4 Giu 2018
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 Commento
Samantha Wallace
Samantha Wallace il 29 Mag 2018
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.

Accedi per commentare.

Risposte (2)

Nikhil Negi
Nikhil Negi il 31 Mag 2018
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 il 4 Giu 2018
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

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by