Info
此问题已关闭。 请重新打开它进行编辑或回答。
Search for timedates in a table
1 次查看(过去 30 天)
显示 更早的评论
Hello, I got a table A 10 rows and 1 column with dates '01/01/2018 O1:00:00' '01/01/2018 02:00:00' ... '01/01/2018 10:00:00'
and for example, I just want to extract from here the values from 01/01/2018 02:00:00 to 01/01/2018 05:00:00, how can i do that?
clear;
clc;
close all;
A = readtable('1.xlsx');
t_start = datetime('01/01/2018 02:00:00');
t_end = datetime('01/01/2018 05:00:00');
for i = t_start:t_end
B = A(i,1);
end
i run this but nothing happens
0 个评论
回答(1 个)
Steven Lord
2018-2-7
From the documentation: "Create a sequence of datetime values starting from November 1, 2013 and ending on November 5, 2013. The default step size is one calendar day."
When you call the colon operator with a datetime as the start and end but no increment, MATLAB will step in increments of 1 day. If you want to step in increments of 1 hour, you will need to specify an increment.
y = t_start:hours(1):t_end
But that probably won't help with the way you're trying to index into your table. If you stored your data in a timetable array instead, you could use timerange and withtol to index into the rows of your timetable for a specific time or range of times.
1 个评论
Peter Perkins
2018-2-7
As Steve says, if you have R2016b or later, this is built into timetable subscripting. In earlier releases, you can use between on the time vector to create a logical vector that will pick out rows of your table.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!