Spliting data based on date
이전 댓글 표시

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
채택된 답변
추가 답변 (2개)
dpb
2014년 12월 23일
2 개 추천
Convert to datenums and then make selections based on those...of course, convert the comparison dates to datenum as well.
댓글 수: 3
Bido12
2014년 12월 23일
Image Analyst
2014년 12월 23일
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
2014년 12월 23일
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
카테고리
도움말 센터 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
