필터 지우기
필터 지우기

pick one value per munite

조회 수: 1 (최근 30일)
Rica
Rica 2016년 5월 20일
편집: Azzi Abdelmalek 2016년 5월 20일
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

채택된 답변

Guillaume
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)

추가 답변 (1개)

Azzi Abdelmalek
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
Rica
Rica 2016년 5월 20일
Hi, thank you for the answer. My array is long. it goes from 15-May to 18-May. the unique function is not approprieate in this cas, i think?
Guillaume
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 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