Effacer les filtres
Effacer les filtres

Select August data from a vector column in the format YYYYMMDD

2 vues (au cours des 30 derniers jours)
Frans
Frans le 11 Déc 2014
Modifié(e) : Peter Perkins le 11 Déc 2014
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

Réponse acceptée

Roger Wohlwend
Roger Wohlwend le 11 Déc 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)];

Plus de réponses (1)

Peter Perkins
Peter Perkins le 11 Déc 2014
Modifié(e) : Peter Perkins le 11 Déc 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

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by