Indexing different time stamps for same day?
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have a table with flight data and i converted the table called 'Manual' to timetable called TT. I would like to extract timesteps of the the data based on timerange indexing . I am confused how to execute the code. The problem is i dont know how to apply all logical indexing to the table TT.I have written 11 logical indexing variables and would like to apply all of them to the Table. As soon as apply t1 , the other logical indexing variables would be useless as the data would be gone from the TT. I am not sure if my approach is correct, what other approaches i can use to filter out the values.
TT=table2timetable(Manual)
t1=timerange('07/24/2021 08:10', '24/07/2021 08:19:30')
t2=timerange('07/24/2021 08:34', '24/07/2021 08:44:30')
t3=timerange('07/24/2021 08:52', '24/07/2021 09:03:30')
t4=timerange('07/24/2021 09:10', '24/07/2021 09:22:00')
t5=timerange('07/24/2021 09:29', '24/07/2021 09:41:00')
t6=timerange('07/24/2021 09:47', '24/07/2021 09:53:30')
t7=timerange('07/24/2021 09:59', '24/07/2021 10:00:00')
t8=timerange('07/24/2021 10:10', '24/07/2021 10:20:00')
t9=timerange('07/24/2021 10:26', '24/07/2021 10:37:30')
t10=timerange('07/24/2021 10:43:30', '24/07/2021 10:56:00')
t11=timerange('07/24/2021 11:01', '24/07/2021 11:11:30')
TT2=TT(t1,:)
0 个评论
采纳的回答
Jack
2023-3-29
If you have multiple conditions that you want to apply to the table, you can use the & operator to combine them into a single logical indexing condition.
For example, if you want to extract only the rows of TT that fall within t1 and also have a certain value in column A, you can write:
idx = TT.Time >= t1.Start & TT.Time <= t1.End & TT.A == 10;
TT2 = TT(idx,:);
Here, idx is a logical array that is true for the rows that satisfy all three conditions, and TT2 contains only those rows.
You can similarly create idx2, idx3, and so on for the other timeranges, and then combine them all using the | operator to get the rows that satisfy any of the conditions:
idx2 = TT.Time >= t2.Start & TT.Time <= t2.End & TT.B > 20;
idx3 = TT.Time >= t3.Start & TT.Time <= t3.End & TT.C == "foo";
% ... and so on for t4 through t11
idx_all = idx1 | idx2 | idx3 | ... | idx11;
TT_filtered = TT(idx_all,:);
Here, idx_all is a logical array that is true for any row that satisfies any of the conditions, and TT_filtered contains only those rows.
Note that you should adjust the column names and conditions in the above code to match your actual table and desired conditions.
0 个评论
更多回答(1 个)
Peter Perkins
2023-4-5
编辑:Peter Perkins
2023-4-5
Arun, as Jack implies, timerange (the class) currently can only represent one interval. You can do one of two things:
1) As Jack suggests, create an explicit logical row index using relational and logical operations on TT.Time ("Time" may have some other name in your case, not sure). That's what time range does behind the scenes.
2) Create all 11 timerange's, use them separately, then vertcat the results:
TT2 = [TT(t1,:); TT(t2,:); ...; TT(t11,:)]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!