I have a 3-d data array of rainfall over an area named PP. The dimensions are (longitud, latitude, time):
So for each time I have a 2-d array which contains the rainfall values for every point in my (x,y). For example, time = 1 (day 1) contains something like this:
0.0 2.2 1.0
4.1 5.0 4.5
2.0 1.9 1.5
and so on. The third column of PP (the time) is the index of each day of my period, which corresponds to the row number in an array called date and looks like this:
date < T x 3 double>
1999 01 01
1999 01 02
1999 01 03
I need the average of the rainfall data over every year (year 1999 mean, year 2000 mean, an so on). I also need the average of all the years during the summer months.
I tried to use accumarray to do the average rainfall over every year. But as elegant/efficient as this function might be, it's hard to understand how it actually works, specially for newbies like me. This is what I tried:
subtot(:,:,t)=accumarray(date(:,1),data(:,:,t), , @mean);
which resulted in:
Error using accumarray
Second input VAL must be a vector with one element for each row in SUBS, or a scalar.
The Matlab documentation is not enough for me to understand how to use the accumarray in this case. Also, I don't understand how to use it when I want to take the average of every summer (Summer 1999, summer 2000, summer 2001, ...)
Am I going in the right direction? If so, how can I properly use the function so it does what I want?
Any help/advice is more than welcome. Thank you for taking your time in advance, and sorry for my poor English.