Extract data corresponding to particular dates

1 view (last 30 days)
I have csv file that contains a variable data every minute along with datetime in the format '2019-01-01 00:00'.
I want to select all data corresponding to particular dates say 12th Jan, 19th Jan, 24th March.
I imported the csv file using readtable and then converted it to timetable. However I am not sure how to select all data corresponding to particular dates. Every selected day should contain 24x60 data values.

Accepted Answer

Star Strider
Star Strider on 19 Nov 2022
Therea re likely several ways to do this.
Using ismember
DT = table(datetime('now')+days(0:364).', 'VariableNames',{'DateTime'});
Data = array2table(randn(365,4));
T1 = [DT Data]
T1 = 365×5 table
DateTime Var1 Var2 Var3 Var4 ____________________ ________ ________ __________ _________ 19-Nov-2022 00:40:28 0.28903 1.7824 -0.42572 -0.86779 20-Nov-2022 00:40:28 -0.71076 0.57947 -0.0023525 -0.38715 21-Nov-2022 00:40:28 -0.51868 0.71015 -0.89238 -1.3137 22-Nov-2022 00:40:28 0.6492 -0.13016 -1.8767 0.58454 23-Nov-2022 00:40:28 -0.8411 -0.40474 -1.0187 -0.66533 24-Nov-2022 00:40:28 0.15967 -1.2587 0.42699 0.013385 25-Nov-2022 00:40:28 1.1346 -0.69719 -2.0905 1.1758 26-Nov-2022 00:40:28 -0.48899 1.1454 -1.2879 -0.54211 27-Nov-2022 00:40:28 1.09 -1.0758 -0.25038 0.88284 28-Nov-2022 00:40:28 0.95017 1.0033 0.4438 0.25697 29-Nov-2022 00:40:28 0.036792 -1.1183 0.15631 -0.84292 30-Nov-2022 00:40:28 1.6097 2.8056 -0.61026 -0.28756 01-Dec-2022 00:40:28 -1.2952 -1.0689 -0.27795 -0.11305 02-Dec-2022 00:40:28 0.08171 -0.47635 -0.81429 -0.098324 03-Dec-2022 00:40:28 -0.47256 -2.5307 -0.12071 -0.12972 04-Dec-2022 00:40:28 -0.16742 1.1085 0.41557 1.3831
[y,m,d] = ymd(T1.DateTime);
query = [1 12; 1 19; 3 24];
Lv = ismember([m d], query, 'rows');
Result = T1(Lv,:)
Result = 3×5 table
DateTime Var1 Var2 Var3 Var4 ____________________ ________ ________ _________ ________ 12-Jan-2023 00:40:28 -1.122 -0.34679 -0.33611 -0.72622 19-Jan-2023 00:40:28 0.57756 -1.2852 -0.11349 -0.85142 24-Mar-2023 00:40:28 -0.71207 -1.1141 -0.095867 0.19215
.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!