# Matlab Date Sorting Program, need help

• Apr 27th 2010, 05:25 PM
aPexDrifta
Matlab Date Sorting Program, need help
Hello, I'm currently trying to write a program which sorts birth dates imported from a text file, in descending order. The data is imported into a matrix of 100 rows and 3 columns; column 1 being the year(yyyy), column 2 being the month(mm), and column 3 being the day(dd). I am able to sort any of the 3 and reference the location of each element so I can swap the rows of each column, but I'm unable to figure out the problem of also sorting the other two columns without screwing up the order of the first. My main issue is that once I get the Year column sorted, the Month and Day columns follow their location just fine, but on elements of the same year, the month and day order are not in proper descending order.

Ex:

Year Month Day
2006 02 05
2006 02 11
2002 05 19
2000 02 18
2000 12 25
2000 10 12
etc...
• Apr 28th 2010, 12:51 AM
CaptainBlack
Quote:

Originally Posted by aPexDrifta
Hello, I'm currently trying to write a program which sorts birth dates imported from a text file, in descending order. The data is imported into a matrix of 100 rows and 3 columns; column 1 being the year(yyyy), column 2 being the month(mm), and column 3 being the day(dd). I am able to sort any of the 3 and reference the location of each element so I can swap the rows of each column, but I'm unable to figure out the problem of also sorting the other two columns without screwing up the order of the first. My main issue is that once I get the Year column sorted, the Month and Day columns follow their location just fine, but on elements of the same year, the month and day order are not in proper descending order.

Ex:

Year Month Day
2006 02 05
2006 02 11
2002 05 19
2000 02 18
2000 12 25
2000 10 12
etc...

Form a composite variable:

ZZZ=dd+100*mm+10000*yyyy;

where dd is the day, mm the month and yyyy the year, now sort on ZZZ

CB