Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Binning values for manipulation

Subject: Binning values for manipulation

From: John Atkinson

Date: 1 Oct, 2010 11:44:23

Message: 1 of 2

Good Day!

Pretty new to Matlab and have been trying and searching for a whole range of functions to try and solve this but struggling,

I have 2 columns of data "x" being a date stamp in the format "yyyymmdd", "y" being a corresponding value to that date, the array coversthe months 12, 01 and 02 of 1953-54 to 2008-2009, and I need to split them into seasonal and monthly bins.

eg

Seasonal would cover 19531201-19540228 (29 in the case of a leap year)
Monthly would cover 19531201-19531231, 19960101-19960131 etc.

Found this script ftp://wise-ftp.tau.ac.il/pub/eran/matlab/TimeSeries/binning.m

which appears to be along the same lines but when i try to base it round this i only get error messages.

Thanks in advance.

Subject: Binning values for manipulation

From: Sean

Date: 1 Oct, 2010 15:29:04

Message: 2 of 2

> I have 2 columns of data "x" being a date stamp in the format "yyyymmdd", "y" being a corresponding value to that date, the array coversthe months 12, 01 and 02 of 1953-54 to 2008-2009, and I need to split them into seasonal and monthly bins.
>
> Seasonal would cover 19531201-19540228 (29 in the case of a leap year)
> Monthly would cover 19531201-19531231, 19960101-19960131 etc.

For seasons
One way:
Create a vector of all edge dates, i.e. dates that lie on the edge of two seasons then use histc.


For months:
Use ACCUMARRAY with the first 6 digits of x being the subs and y being the vals. Then depending on what you want set up the function to do that. If you want a numeric result something like sum or prod use that. If you want all of the values associated with the date use something along the lines of @(x){x} to return a cell array with all values.

You could also calculate the months first and then just bin them with each other for seasons seeing as how every 3 months equals one season:
e.g. 200 seasons total
season_idxs = reshape(repmat(1:200,[3,1]),[],1);
accumarray(season_idxs,months,[],fun)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us