Select values based on datetime

stelios loizidis · Apr 17, 2023 · 1.8K views
Question
Hello,   I have the matrix Values (1X2100) and the corresponding DateTime matrix with datetime data (1x2100 datetime). The values in Values matrix are hourly. I want to categorize the values of the Values table into 3 categories. I wrote the following codes for categorization,   [k1,i1]=find(Values<0); [k2,i2]=find(0<=Values & Values<=80; [k3,i3]=find(80
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Nov 20, 2025
The very first thing you should do is put your data and timestamps in a timetable.
 
Once you do that, use retime to create a daily timetable, using your own custom aggregation function that returns 1, 2, or 3 according to your rules ("the same dates that exist in Cat_Time_1 and Cat_Time_2 stay in Cat_Time_1 and leave Cat_Time_2 ...", which I don't really understand but you should be able to write that function.
 
Now you have a list of days and what category they are in. Use dateshift on your original timetable to add a new variable that is the day timetamp, use join to combine that with the daily timetable, and select data from tyhat using the category number.
 
The custom function aside, this is just a few lines of code. No loops needed.
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!