Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Search for timedates in a table

1 vue (au cours des 30 derniers jours)
Tiago Dias
Tiago Dias le 7 Fév 2018
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (1)

Steven Lord
Steven Lord le 7 Fév 2018
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 commentaire
Peter Perkins
Peter Perkins le 7 Fév 2018
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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by