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!