|
Thanks a lot for the help, despite my lame explanation you got it! I see what I was doing wrong. I needed to make a matrix the correct size to store the results, in this case the matrix 'i'. And as yr is a logical array, they are all one, and summing this will give the number of values.
THANKS!
"Pj English" <northern69@yahoo.com> wrote in message <gp3u6d$bfg$1@fred.mathworks.com>...
> "Dave " <yogi_cave@yahoo.com> wrote in message <gouo0t$c2g$1@fred.mathworks.com>...
> > Hi, I need some help building on the simple code i made below. this averages the values in column 6 by year (:,2) in the the matrix A. there is generally a data point for every day in each year, however some points are missing.
> >
> > year=A(:,2);
> > day = A(:,3);
> >
> > for year=1996:1:2006;
> >
> > yr=A(:,2)==year;
> > M(yr,3)=mean(A(yr,6));
> >
> >
> > end
> >
> > the output creates a row for day in every year. firstly, is there a way of outputting the number of data points that were used to calculate each average? and secondly is there a way to make it output only one line per year?
> >
>
> Try this:
>
> for i = 1 : 11
> year = 1995 + i;
> yr = A(: , 2) == year;
> M(i, 3) = mean(A(yr,6));
> N(i) = sum(yr);
> end
>
> M(:, 3) is your mean values. N is a vector giving the number of entries used to calculate each mean.
> >
> > Dave
|