Spliting data based on date
Show older comments

How can we split data into sub arrays based on dates? Lets say we do have thousands data points for different dates (for a week) . I want to split this data into arrays based on the dates as the number of observations is changing from date to date. The following is a sample from my data. Many thanks in advance
Accepted Answer
More Answers (2)
dpb
on 23 Dec 2014
2 votes
Convert to datenums and then make selections based on those...of course, convert the comparison dates to datenum as well.
3 Comments
Bido12
on 23 Dec 2014
Image Analyst
on 23 Dec 2014
Considering that you haven't even told us what form or format your dates are in, we don't know either. You say you've "tried a lot" but you didn't share any of those with us. What did you try? Can you provide any data? Have you read this yet?
Guillaume
on 23 Dec 2014
Most likely, you want to use the third return value unique on datenums or datevecs to find out how to split your data, and possibly accumarray to perform operations on the other columns.
For example:
data = [2014 12 19 1
2014 12 19 1.2
2014 12 20 2.2
2014 12 19 1.4
2014 12 20 2
2014 12 20 2.6
2014 12 20 2.4
2014 12 21 3.5]; %year month day value
[dates, ~, dateidx] = unique(data(:, 1:3), 'rows'); %find out where the dates go
dataperday = arrayfun(@(idx) data(dateidx==idx, 4), 1:size(dates, 1), 'UniformOutput', false)'; %split into cell arrays
averageperday = accumarray(rows, data(:, 4), [], @mean); %calculate mean per day
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!