How to seperate data stored as a table in matlab into multiple tables based on the date.
조회 수: 4 (최근 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!