Matlab Date Sorting Program, need help
aPexDrifta
NY
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...
Ex:
Year Month Day
2006 02 05
2006 02 11
2002 05 19
2000 02 18
2000 12 25
2000 10 12
etc...
0
Comments
As for the code, I don't really have much saved at the moment, it's mostly been trial and error in the command window.
So yeah, I'm pretty much stuck on trying to keep the year column in the same order, while just re-sorting the months and days within each section of years.
Here is my function: age
Some of the code from my program:
And the error I receive after I run:
Once again, any feedback is appreciated,
you're looping over the length of birthdates with the variable n, but you're not using n to index either BirthDates(:,2) or Birthdates(:,3). you might want them to be BirthDates(n,2) and 3.
If that's not the issue, i'll take a closer look.