how to sort cells by date?

i have a column of dates DD\MM\YYYY, i want to sort them by date .
i try:
sort(A);
but it sorts them by days
how i can do this?

2 Comments

Is 11\5\2007 before or after 11/5/2007 ?
Are you joking? what do you mean?

Sign in to comment.

Answers (1)

[~, order] = datenum(A(:,1));
sortedA = A(order,:);

3 Comments

it gives me an error:
Error using datenum
Too many output arguments.
I use:
[ndata text alldata] = xlsread('defibrillator failures 98 to 10.xlsx','alldate');
[R2,C2]=size(alldata);
A=alldata;
[~, order] = datenum(A(:,1));
sortedA = A(order,:);
[~, order] = sort(datenum(A(:,1)));
sortedA = A(order,:);
Thanks... it works, but it didn't sort all of them.
as I discovered that some of dates written in the form "dd/mm/yyyy" and others "mm/dd/yyyy".
so it seems that I have to convert them first to one form.

Sign in to comment.

Categories

Asked:

on 24 Aug 2015

Commented:

on 24 Aug 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!