Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Search for timedates in a table

1 visualización (últimos 30 días)
Tiago Dias
Tiago Dias el 7 de Feb. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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

Respuestas (1)

Steven Lord
Steven Lord el 7 de Feb. de 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 comentario
Peter Perkins
Peter Perkins el 7 de Feb. de 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.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by