extract especific rows from matrix
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Star Strider
on 23 Oct 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')
TT1 = table2timetable(T1)
newTimes = TT1.c1(1):minutes(30):TT1.c1(end);
TT2 = retime(TT1,'regular','fillwithmissing','TimeStep',minutes(30))
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 Comments
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!