pick one value per munite
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all,
i have such an date time Array:
'18-May-2016 14:04:17'
'18-May-2016 14:05:07'
'18-May-2016 14:05:54'
'18-May-2016 14:06:43'
'18-May-2016 14:07:34'
'18-May-2016 14:08:25'
'18-May-2016 14:09:15'
'18-May-2016 14:10:07'
'18-May-2016 14:10:57'
'18-May-2016 14:11:48'
'18-May-2016 14:12:39'
'18-May-2016 14:13:30'
'18-May-2016 14:14:22'
'18-May-2016 14:15:12'
'18-May-2016 14:16:03'
'18-May-2016 14:16:54'
how could i clear the repeated munite values? for exemple : 18-May-2016 14:05:54 , '18-May-2016 14:10:07' and '18-May-2016 14:16:54'.
Thank you all
댓글 수: 0
채택된 답변
Guillaume
2016년 5월 20일
편집: Guillaume
2016년 5월 20일
To start with, I would convert the datestr array to datetime and just work with that for the rest of your code.
To perform the filtering, you use unique as per Azzi's answer:
A={'18-May-2016 14:04:17'
'18-May-2016 14:05:07'
'18-May-2016 14:05:54'
'18-May-2016 14:06:43'
'18-May-2016 14:07:34'
'18-May-2016 14:08:25'
'18-May-2016 14:09:15'
'18-May-2016 14:10:07'
'18-May-2016 14:10:57'
'18-May-2016 14:11:48'
'18-May-2016 14:12:39'
'18-May-2016 14:13:30'
'18-May-2016 14:14:22'
'18-May-2016 14:15:12'
'18-May-2016 14:16:03'
'18-May-2016 14:16:54'}
A = datetime(A); %convert to datetime. In your cases, datetime is clever enough that you don't even need to specify the format
[~, indextokeep] = unique(A.Minute); %see how easy it is to extract the minutes
filteredA = A(indextokeep)
댓글 수: 0
추가 답변 (1개)
Azzi Abdelmalek
2016년 5월 20일
편집: Azzi Abdelmalek
2016년 5월 20일
A={'18-May-2016 14:04:17'
'18-May-2016 14:05:07'
'18-May-2016 14:05:54'
'18-May-2016 14:06:43'
'18-May-2016 14:07:34'
'18-May-2016 14:08:25'
'18-May-2016 14:09:15'
'18-May-2016 14:10:07'
'18-May-2016 14:10:57'
'18-May-2016 14:11:48'
'18-May-2016 14:12:39'
'18-May-2016 14:13:30'
'18-May-2016 14:14:22'
'18-May-2016 14:15:12'
'18-May-2016 14:16:03'
'18-May-2016 14:16:54'}
a=datevec(A,'dd-mm-yyyy HH:MM:SS')
min1=a(:,end-1)
[~,ii]=unique(min1,'stable');
out=A(ii,:)
댓글 수: 2
Guillaume
2016년 5월 20일
편집: Guillaume
2016년 5월 20일
@Azzi, please don't use min as a variable name (overrides the min function). You're teaching bad habits in your examples!
@Rica, well you're asking to remove duplicates and hence to obtain unique minutes. The unique function is the most appropriate for this. The length of your array is irrelevant, whichever scheme you could come up with will be slower than unique.
Also, I would recommend using datetime instead of datevec. As a matter of fact, I would simply convert the datestring array into datetime and just use that for future processing. datetime is a lot easier to use
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!