Thread Subject: average every 12th row of matrix

Subject: average every 12th row of matrix

From: Nix Nicholson

Date: 5 Nov, 2009 17:19:03

Message: 1 of 5

Hi: Beginner question - I have 7 years of some monthly data fields and I want to compute the average for each month over the 7 year period. I can do it by specifying row numbers but how could I do this so that come next year, when i have 8 years data I can just change a scaler value for year number and it will recompute a new average?
basically how do i compute a mean of every nth row, in my case every 12th.

Many thanks

Subject: average every 12th row of matrix

From: the cyclist

Date: 5 Nov, 2009 17:30:35

Message: 2 of 5

"Nix Nicholson" <linznix@gmail.com> wrote in message <hcv1e7$3ua$1@fred.mathworks.com>...
> Hi: Beginner question - I have 7 years of some monthly data fields and I want to compute the average for each month over the 7 year period. I can do it by specifying row numbers but how could I do this so that come next year, when i have 8 years data I can just change a scaler value for year number and it will recompute a new average?
> basically how do i compute a mean of every nth row, in my case every 12th.
>
> Many thanks

You should be able to user the FILTER command to do this.

Subject: average every 12th row of matrix

From: Matt

Date: 5 Nov, 2009 17:30:36

Message: 3 of 5

"Nix Nicholson" <linznix@gmail.com> wrote in message <hcv1e7$3ua$1@fred.mathworks.com>...
> Hi: Beginner question - I have 7 years of some monthly data fields and I want to compute the average for each month over the 7 year period. I can do it by specifying row numbers but how could I do this so that come next year, when i have 8 years data I can just change a scaler value for year number and it will recompute a new average?
> basically how do i compute a mean of every nth row, in my case every 12th.

Instead of organizing your data as a vector, you can organize it as an Nx12 matrix A where N is the number of years. Then do

MonthlyMeans=mean(A,1);

When you have N=8, just add a row and do the same thing.

Subject: average every 12th row of matrix

From: dpb

Date: 5 Nov, 2009 17:26:55

Message: 4 of 5

Nix Nicholson wrote:
> Hi: Beginner question - I have 7 years of some monthly data fields
> and I want to compute the average for each month over the 7 year
> period. I can do it by specifying row numbers but how could I do this
> so that come next year, when i have 8 years data I can just change a
> scaler value for year number and it will recompute a new average?
> basically how do i compute a mean of every nth row, in my case every
> 12th.
...

idx=1:12:length(x);
avg = mean(idx,:);

Salt to suit on selecting starting month, etc., ...

--

Subject: average every 12th row of matrix

From: dpb

Date: 5 Nov, 2009 18:32:02

Message: 5 of 5

dpb wrote:
> Nix Nicholson wrote:
>> Hi: Beginner question - I have 7 years of some monthly data fields
>> and I want to compute the average for each month over the 7 year
>> period. I can do it by specifying row numbers but how could I do this
>> so that come next year, when i have 8 years data I can just change a
>> scaler value for year number and it will recompute a new average?
>> basically how do i compute a mean of every nth row, in my case every
>> 12th.
> ...
>
> idx=1:12:length(x);
> avg = mean(idx,:);
>
> Salt to suit on selecting starting month, etc., ...

Should have been

avg = mean(x(idx,:));

of course...

--

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com