필터 지우기
필터 지우기

Finding unique dates in vector

조회 수: 23 (최근 30일)
Mads
Mads 2011년 5월 25일
Hi all.
I have a vector of dates where each date is repeated many times. How would i create a vector with every date but no repetitions efficiently?
Thx.
  댓글 수: 1
Jan
Jan 2011년 5월 25일
What exactly means "vector of dates"? Please post the type of the input exactly. I assume that UNIQUE will help you directly.

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 5월 25일
Date = ['02-Aug-2010 19:28:01'
'13-Nov-2010 09:10:20'
'10-Nov-2010 14:44:14'
'02-Aug-2010 19:28:01'
'08-Oct-2010 08:58:46'
'30-Jan-2010 08:24:16'
'10-Nov-2010 14:44:14'
'13-Nov-2010 09:10:20'
'08-Oct-2010 08:58:46']
[a n] = unique(datenum(Date));
D1 = sortrows([a n],2);
Dout = datestr(D1(:,1));
Hi Jan! agree with you. In our case, it is possible and so:
[a n] = unique(Date,'rows')
[~,idx] = sort(n);
Dout = a(idx,:);
  댓글 수: 4
Andrei Bobrov
Andrei Bobrov 2011년 5월 25일
Hi Jan! agree with you.
Matt Tearle
Matt Tearle 2011년 5월 25일
...assuming that the dates are all in the exact same format. Andrei's solution (going via datenum) avoids the problem of two different formats for the same date. (Unlikely, but it could happen.)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by