How to organise data based on a large range of numbers?
Show older comments
I have a set of data that needs to be organised by season. Each row represents a different sample with each column representing the different data collected for each sample. Column 8 represents the day of the year the sample was collected so I want to use this to get an estimate of the season in which the sample was collected, ie. if the day of the year is from 1-59 as well as 335-366 the data was collected in summer, if the day of the year the sample was collected was between the 60th and the 151st day of the year then the sample was collected in Autumn, and so on.... As the seasons encompass numerous days of the year I have been finding it difficult to extract organise the data into seasons. I was wondering if anyone knew as to how this could be done? Thanks
Accepted Answer
More Answers (1)
Andrei Bobrov
on 21 Oct 2013
ssn = {'summer','autumn','winter','spring'};
d = [31 28 31 30 31 30 31 31 30 31 30 31];
dd = cumsum(d');
b = [1;dd(cumsum([2 3 3 3 1]'))];
x = sort(randi(365,20,1)); % Let x is data as column 8 from your data
[~,ii] = histc(x,b);
ii(ii==5) = 1; % or ii = rem(ii-1,4)+1;
out = ssn(ii);
Categories
Find more on Multivariate Distributions 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!