How to seperate data stored as a table in matlab into multiple tables based on the date.

4 visualizzazioni (ultimi 30 giorni)
I have datathat is 156848 x 4 cell. The data is from an Arduino data logger used to measure light levels and apply a time/date to each reading. I have 4 columns in the table, the first is the time and date at 8 second intervals, 2nd is the light level from one sensor, 3rd another light sensor, 4th another sensor. I completed an experiment over 14 days where I collected this data. I have the large dataset as a table in Matlab but I now wish to separate this table into individual days and perhaps 12 hour bins later. I need to separate this data into multiple tables based on the specific date. Any idea how to do this using R2017b ? Any help is greatly appreciated.
  1 Commento
Guillaume
Guillaume il 10 Apr 2018
Note: cell arrays and tables are two different types. According to your screenshot, what you have is a 156848x4 table not a cell array.

Accedi per commentare.

Risposte (2)

KSSV
KSSV il 10 Apr 2018
YOu can convert your dates into vector using datevec, from this pick the similiar day indices....and form a table with these indices. Read about datevec.
  1 Commento
Guillaume
Guillaume il 10 Apr 2018
Modificato: Guillaume il 10 Apr 2018
Why would you convert a datetime variable into the less efficient, more awkward to use, and outdated datevec? In particular, discretize (which may be useful if you actually wanted to split the data) does not work with datevec but does with datetime.

Accedi per commentare.


Guillaume
Guillaume il 10 Apr 2018
Modificato: Guillaume il 10 Apr 2018
Any idea how to do this using R2017b
Yes, don't do it! In general splitting one variable into multiple variables is a bad idea. Whatever further processing you want to do later will be easier if you don't split the data. In particular, if you want to calculate daily (or 12-hours) statistics then splitting the table into multiple tables is a very bad idea.
Firstly, I'd recommend you convert the table into a timetable with table2timetable:
sensorlog = table2timetable(yourtable);
You can then easily calculate daily statistics with retime
dailymean = retime(sensorlog, 'daily', 'mean');
or in steps of 12 hours:
halfdaymean = retime(sensorlog, hours(12), 'mean');
Other options to calculate aggregates include using the Split-Apply-Combine workflow or varfun with the 'GroupBy' option. All of these don't work if your data is split into multiple variables. discretize may also be useful.
  1 Commento
Peter Perkins
Peter Perkins il 11 Apr 2018
This
halfdaymean = retime(sensorlog, hours(12), 'mean')
isn't quite right: it retimes to a time vector with one element. Prior to R2018a, you'd need to use a combination of dateshift and start:hours(12):stop to build the target time vector.
In R2018a:
halfdaymean = retime(sensorlog, 'regular', 'mean', 'TimeStep',hours(12))

Accedi per commentare.

Categorie

Scopri di più su Timetables 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