Borrar filtros
Borrar filtros

Select August data from a vector column in the format YYYYMMDD

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Roger Wohlwend
Roger Wohlwend el 11 de Dic. de 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)];

Más respuestas (1)

Peter Perkins
Peter Perkins el 11 de Dic. de 2014
Editada: Peter Perkins el 11 de Dic. de 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

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by