Select August data from a vector column in the format YYYYMMDD
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Frans
il 11 Dic 2014
Modificato: Peter Perkins
il 11 Dic 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
0 Commenti
Risposta accettata
Roger Wohlwend
il 11 Dic 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 Commenti
Più risposte (1)
Peter Perkins
il 11 Dic 2014
Modificato: Peter Perkins
il 11 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!