How can I extract a specific time for a "datetime" table?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ashfaq Ahmed
am 15 Feb. 2023
Beantwortet: dpb
am 15 Feb. 2023
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 Kommentare
Akzeptierte Antwort
Kevin Holly
am 15 Feb. 2023
Bearbeitet: Kevin Holly
am 15 Feb. 2023
load('RESULT.mat')
result
result.HourSeries = datetime(result.HourSeries,"Format","HH:mm")
index = hour(result.HourSeries)==12|hour(result.HourSeries)==2;
result(index,:)
Weitere Antworten (2)
Sulaymon Eshkabilov
am 15 Feb. 2023
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
am 15 Feb. 2023
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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!