Simple wild card function for ismember??
显示 更早的评论
I have a list of dates and times as string values and (e.g '29/1/2010 20:30:00' etc) and I would like to find all values at a specific time, regardless of day.
Is there a simple wild card function that I can use with ismember to identify these? I have tried:
idx = ismember(Timestamp_str, {'*20:30:00'});
I have also tried regexp, searched the web and help files to no avail.....
采纳的回答
更多回答(2 个)
Andrei Bobrov
2011-7-19
d1 = datenum(Timestamp_str);
d2 = datenum('00/0/0000 20:30:00');
out = Timestamp_str(abs(rem(d1,1)-d2)<1e6*eps,:)
ADD variant with 'datevec'
dv = datevec(Timestamp_str);
out = Timestamp_str(all(bsxfun(@eq,dv(:,4:6),[20 30 0]),2),:);
adding in answer on the comment Walter's about milliseconds
dv(:,end) = round(dv(:,end));
dv = datevec(datenum(dv));
3 个评论
Walter Roberson
2011-7-19
Would it be more robust to datevec() and look at the components ?
Andrei Bobrov
2011-7-19
Dear Walter! I completely agree with you and thinking about using 'datevec'.
Add variant with 'datevec'
Walter Roberson
2011-7-19
Though 20:29:59.5 and up to but excluding 20:30:00.5 would probably print out as 20:30:00, so rounding the seconds + milliseconds combination might be called for.
Jan
2011-7-19
idx = strncmpr(Timestamp_str, '20:30:00', 8);
类别
在 帮助中心 和 File Exchange 中查找有关 Calendar 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!