Matlab (more generally: sorting data by date)

I'm not sure if this really belongs anywhere on this forum but my previous experiences on here have shown me that you guys are very helpful so I figure I may as well try.

I have a bunch of large 2d arrays in matlab and each has a column for a date that each row corresponds to. The format is yymmdd except for everything for 2000 which is just mmdd.

I need to be able to separate the data based on season (ie DJF, MAM, JJA, SON) but I'm not sure what is the best way to go about it based on the format of the data. I could write a bunch of if statements to decide each season but the 2000 data complicates that method.

Any advice (you don't have to write anything out) would be much appreciated. It's been a few years since my last programming class and I can't remember the best practice for this. :slight_smile:

All you care about is the mm part.

Programatically I would transform the date column in the array, to a 'season value' before doing any sorting.

Create a vector (assuming zero based) S with 12 elements s[0..2] == 0 (Spring),
s[3..5] == 1 (Summer) and so on.

For each row in your array, get the mm substring from the date. Convert the mm to an integer say i, replace the date value in the column with s[i]. Use a length(column) to see if the year 2000 problem exists.

If you sort numerically on the transformed date column, you get seasonal order. You can also preserve the date by adding another column to the array, transforming into it, then sorting.