Extract rows from matrix based on date
Show older comments
I have a 88416 x 11 matrix. Hourly date and time datenum values are in column 1. The hourly date range is from 2006-12-1 to 2016-12-31. If the date is 2007-10-28 I want to remove it from the matrix and create a new matrix that contains it and all the values in that row. I want to repeat this for several dates. How do I do it?
Accepted Answer
More Answers (1)
Peter Perkins
on 9 May 2017
David, even prior to R2016b, you might look at using datetimes rather than datenums:
>> d = datetime(2017,10,26,(0:60:420)',0,0)
d =
8×1 datetime array
26-Oct-2017 00:00:00
28-Oct-2017 12:00:00
31-Oct-2017 00:00:00
02-Nov-2017 12:00:00
05-Nov-2017 00:00:00
07-Nov-2017 12:00:00
10-Nov-2017 00:00:00
12-Nov-2017 12:00:00
>> ( '28-Oct-2017'<= d & d<'11-Nov-2017' )'
ans =
1×8 logical array
0 1 1 1 1 1 1 0
Put d and the rest of your data in a table, and although you don't get everything that timetables provide, you might find it easier to subset your data.
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!