"Cris Luengo" <cris.luengo@google.for.my.name.to.contact.me> wrote in message <i9s243$dj8$1@fred.mathworks.com>...
> "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rdlo$bni$1@fred.mathworks.com>...
> > "Glauston Lima" <glau11@gmail.com> wrote in message <i9r3j7$e8o$1@fred.mathworks.com>...
> > > My friends,
> > >
> > > suppose I have the matrix A=
> > > [1 4 6 7 8
> > > 5 0 2 3 3
> > > 9 4 8 5 2
> > > 1 0 7 2 1]
> > >
> > > and suppose I need to calculate (separately) the average of the columns (1, 2, 4) and the average of the columns (3, 5). Namely, I want to get the average of matrices:
> > >
> > > [1 4 7 [6 8
> > > 5 0 3 2 3
> > > 9 4 5 8 2
> > > 1 0 2] 7 1]
> > >
> > > My question is as follows:
> > >
> > > is there any Matlab command that returns these averages all at once?
> > >
> > > Please understand: I'd like to know if it is possible to calculate the averages using a single Matlab command, without the need of loops .
> > >
> > > Thank you in advance for your attention
> > >
> > > Glauston
> >
> > Hi Glaustone,
> > if you need an average (not averages) you have to do it in two steps in your problem:
> > m124 = mean(A(:,1);A(:,2);A(:,4));
> > m35 = mean(A(:,3);A(:,5));
> > Is it OK?
> > In general case, you put the indeces of columns in the vector ix, say ix=(1,2,4),
> > make a new matrix of selected columns As = A(,:ix) and calculate mean(As(:));
> > It is all.
> > Mira
>
> Another way is to compute the average of all columns first:
> m = mean(A);
> and then average together the columns you need:
> [mean(m([1,2,4)),mean(m([3,5]))]
>
> Cheers,
> Cris.
Or by the oneliner
means = mean(A(:,[1,2,4,3,5]))
Mira
