フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Search for timedates in a table

1 回表示 (過去 30 日間)
Tiago Dias
Tiago Dias 2018 年 2 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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

回答 (1 件)

Steven Lord
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
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!

Translated by