# How to calculate the median for each day of the year in 91 years?

2 vues (au cours des 30 derniers jours)
Maria Mateus le 9 Oct 2013
Commenté : Matt Kindig le 9 Oct 2013
I need to calculate the median value for each day of the year from a period of record that goes from Jan 1st 1915 to Dec 31 2006 (ie: median values for: 01-01-1915, 01-01-1016,...,01-01-2006).
The matrix is organized in the following order:
Year Month Day Streamflow_A1B Streamflow_B1 1915 01 01 1000 1010 1915 01 02 1100 1050 1915 01 03 2000 2100 ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 2006 12 31 2000 2100
Any help with this will be very much appreciated. I am new at Matlab.
Thanks!
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (2)

Matt Kindig le 9 Oct 2013
Modifié(e) : Matt Kindig le 9 Oct 2013
I think this is a good use of accumarray().
%some sample data, to illustrate approach
Data = [1915 1 1 1000 1010;
1915 1 2 1100 1050;
1915 1 3 2000 2100;
1918 1 1 500 800;
1918 1 2 1000 600;
2006 12 31 2000 2100;
2008 12 15 1800 1920];
%break into variables
Days = Data(:,2:3);
StreamA1B = Data(:,4);
StreamB1 = Data(:,5);
%get unique month/day combinations. Note, not all months will have the same
%number of days! Leap years can also complicate things a bit.
[MonthDays, ~, index] = unique( Days, 'rows');
%calculate median by day
StreamA1B_med = accumarray(index, StreamA1B, [], @median);
SreamB1_med = accumarray(index, StreamB1, [], @median);
##### 2 commentairesAfficher AucuneMasquer Aucune
Azzi Abdelmalek le 9 Oct 2013
Maria commented
Thanks! However, this only gives me values for each day (1 to 31), right? I need to calculate this for each day of the year, that is for each day one in Jan, each day one in Feb, etc.
Thanks!
Matt Kindig le 9 Oct 2013
No, this should give you all days of the month. If you look at the MonthDays variable, you'll see that all month/day combinations are covered.

Connectez-vous pour commenter.

Maria Mateus le 9 Oct 2013
Never mind. I got it. Thanks!
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Time Series 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