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.
"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.
"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.
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., ...
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.
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.