extract especific rows from matrix

1 visualización (últimos 30 días)
Armin Azad
Armin Azad el 23 de Oct. de 2021
Comentada: Star Strider el 24 de Oct. de 2021
Hi, I have a two columns data. The first column includes time yyyymmddhhmm (which means Year; month; day, hour and minutes). The second column contains numerical data. The interval between time tables are 15 minutes so you see the first row is 202002041000 and the second row is 202002041015.
I have a very big matrix (3500*2) and some times some data are missed, so the pattern is not uniform. I want to write a code to extract the rows which are for every 30 minutes (the rows that ends to 30). So maybe a code which check whether the first column data ends to 30 helps.
Could you please help me with this
202002041000 25
202002041015 35
202002041030 54
202002041045 54
202002041100 23

Respuesta aceptada

Star Strider
Star Strider el 23 de Oct. de 2021
One option —
c = [202002041000 25
202002041015 35
202002041030 54
202002041045 54
202002041100 23
202002041200 23]; % Last Row Added To Test Code
T1 = array2table(c);
T1.c1 = datetime(num2str(T1.c1),'InputFormat','yyyyMMddHHmm')
T1 = 6×2 table
c1 c2 ____________________ __ 04-Feb-2020 10:00:00 25 04-Feb-2020 10:15:00 35 04-Feb-2020 10:30:00 54 04-Feb-2020 10:45:00 54 04-Feb-2020 11:00:00 23 04-Feb-2020 12:00:00 23
TT1 = table2timetable(T1)
TT1 = 6×1 timetable
c1 c2 ____________________ __ 04-Feb-2020 10:00:00 25 04-Feb-2020 10:15:00 35 04-Feb-2020 10:30:00 54 04-Feb-2020 10:45:00 54 04-Feb-2020 11:00:00 23 04-Feb-2020 12:00:00 23
newTimes = TT1.c1(1):minutes(30):TT1.c1(end);
TT2 = retime(TT1,'regular','fillwithmissing','TimeStep',minutes(30))
TT2 = 5×1 timetable
c1 c2 ____________________ ___ 04-Feb-2020 10:00:00 25 04-Feb-2020 10:30:00 54 04-Feb-2020 11:00:00 23 04-Feb-2020 11:30:00 NaN 04-Feb-2020 12:00:00 23
This fills the missing data with NaN. To interpolate the missing values instead, replace 'fillwithmissing' with 'linear' or any of the other applicable options.
It would help to have more data, especially with missing times and more detail on the desired result for the missing data, however this will work for a start.
See the documentation for the various functions to understand how the code works.
.
  11 comentarios
Armin Azad
Armin Azad el 24 de Oct. de 2021
Thank you so much. I could successuly do that in Matlab online 2021b.
Thanks again.
Star Strider
Star Strider el 24 de Oct. de 2021
As always, my pleasure!
.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by