How can I extract a specific time for a "datetime" table?
14 次查看(过去 30 天)
显示 更早的评论
Dear coders,
I have a simple question but I am confused how to code it. I have this datetime table (attached with the question: RESULT.mat) and I want to keep only those rows that contains time between 2:00-3:00 am and 12:00-13:00 pm. As shown in this picture -
The final datetime table should contain only these rows with the desired HourSeries. Any feedback from you will be highly appreciated! <3
0 个评论
采纳的回答
Kevin Holly
2023-2-15
编辑:Kevin Holly
2023-2-15
load('RESULT.mat')
result
result.HourSeries = datetime(result.HourSeries,"Format","HH:mm")
index = hour(result.HourSeries)==12|hour(result.HourSeries)==2;
result(index,:)
更多回答(2 个)
Sulaymon Eshkabilov
2023-2-15
Here is one partial answer that finds the data pointsat specific times, i.e. 02:00, 03:00, 12:00, 13:00 and overlooks other time points such as s12:08, for example:
R =load('RESULT.mat').result;
IDX1 = find(ismember(R.HourSeries, '02:00'));
IDX2 = find(ismember(R.HourSeries, '03:00'));
IDX3 = find(ismember(R.HourSeries, '12:00'));
IDX4 = find(ismember(R.HourSeries, '13:00'));
Rs = R([IDX1,IDX2, IDX3, IDX4, IDX4],:); % Selected
whos R Rs
dpb
2023-2-15
result.HourSeries=duration(result.HourSeries,'InputFormat','hh:mm');
ix=isbetween(result.HourSeries,hours(2),hours(4))|isbetween(result.HourSeries,hours(12),hours(13));
result=result(ix,:);
Keeps only the selected entries; you lose the rest and would have to reload the .mat file if need any other data. Doing the conversion and reSAVEing first would probably be the smart thing; then save that step going forward.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!