Select August data from a vector column in the format YYYYMMDD
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Roger Wohlwend
2014년 12월 11일
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
추가 답변 (1개)
Peter Perkins
2014년 12월 11일
편집: Peter Perkins
2014년 12월 11일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!