how to count data frequency by year and month?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, i want to plot a hsitogram count of stations function of Year/month i have number of station by montn and by year i have 163x20char indicating name of station and time 163x20char in format dd-mmm-yyyy station_code: 405, 406, 500, 501, 430 and time: 02-dec-2010,02-dec-2010,20-may-2009, 06-august-2015, 06-sept-2008 any suggestion please
Respuestas (1)
Cris LaPierre
el 11 de Ag. de 2020
Easier to help if you share your data.
Now you can create a histogram of time, grouping the data by station name or station_code. Use dateshift to specify the edges of your histogram bins, with 1 calendar month spacing between edges.
% Create sample data
station = ['my station name 1 ';
'my station name 2 ';
'my station name 3 ';
'my station name 4 ';
'my station name 5 ']
station_code=[405; 406; 500; 501; 430]
% Dates all have to have the same format to be converted to datetimes
% I have therefore edited the last two entries to also use MMM format.
time = {'02-dec-2010','02-dec-2010','20-may-2009', '06-aug-2015', '06-sep-2008'}
% convert station info to categoricals, time to datetime.
station = categorical(string(station))
station_code = categorical(station_code)
time = datetime(time,"InputFormat","dd-MMM-yyyy")
% Specify bin edges
edges = dateshift(min(time),"start","month"):calmonths(1):dateshift(max(time),"start","month","next")
% Create the histogram
histogram(time,edges)
Each bar is one month wide. If you zoom in using the axes toolbar, you'll be able to see the month and year under the bar.
0 comentarios
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!