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일

1 개 추천

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

댓글 수: 3

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,:);
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2015년 8월 24일

댓글:

2015년 8월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by