Select August data from a vector column in the format YYYYMMDD
1 view (last 30 days)
Show older comments
Hi,
I have two vector columns, one containing the dates in the format YYYYMMDD for 10 years, and in the other column the amount of rainfall in mm. I want to create a matrix, or two vector columns, containing only the months of august with the corresponding rainfall. Any ideas how to achieve this?
Thanks in advance
0 Comments
Accepted Answer
Roger Wohlwend
on 11 Dec 2014
First convert your time vector into a vector that contains the date as a number.
Date = datenum(Date_Vector,'YYYYMMDD');
Now search for August.
q = month(Date) == 8;
Create your matrix.
AugustRainfallMatrix = [Date(q), Rainfall(q)];
0 Comments
More Answers (1)
Peter Perkins
on 11 Dec 2014
Edited: Peter Perkins
on 11 Dec 2014
Are the dates strings, or numbers?
If you have access to R2014b, you could do either of these, depending on which you have:
>> c % cell array of strings
c =
'20141201'
'20141202'
'20141203'
'20141204'
'20141205'
>> month(datetime(c,'Format','yyyyMMdd'))
ans =
12
12
12
12
12
>> x % integer values
x =
20141201
20141202
20141203
20141204
20141205
>> month(datetime(x,'convertFrom','YYYYMMDD'))
ans =
12
12
12
12
12
0 Comments
See Also
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!