how to sort cells by date?

3 次查看(过去 30 天)
Amr Hashem
Amr Hashem 2015-8-24
评论: Amr Hashem 2015-8-24
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 个评论
Walter Roberson
Walter Roberson 2015-8-24
Is 11\5\2007 before or after 11/5/2007 ?
Amr Hashem
Amr Hashem 2015-8-24
Are you joking? what do you mean?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2015-8-24
[~, order] = datenum(A(:,1));
sortedA = A(order,:);
  3 个评论
Walter Roberson
Walter Roberson 2015-8-24
编辑:Walter Roberson 2015-8-24
[~, order] = sort(datenum(A(:,1)));
sortedA = A(order,:);
Amr Hashem
Amr Hashem 2015-8-24
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by