How to seperate data stored as a table in matlab into multiple tables based on the date.
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Guillaume
2018-4-10
Note: cell arrays and tables are two different types. According to your screenshot, what you have is a 156848x4 table not a cell array.
回答(2 个)
KSSV
2018-4-10
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 个评论
Guillaume
2018-4-10
编辑:Guillaume
2018-4-10
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.
sensorlog = table2timetable(yourtable);
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 个评论
Peter Perkins
2018-4-11
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))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Timetables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!