Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Jos
Posts:
1,268
Registered:
10/24/08


Re: Avergaing Matrix.
Posted:
Feb 4, 2013 4:36 AM


"Linus " <linus.ang@live.com> wrote in message <ken744$5je$1@newscl01ah.mathworks.com>... > Hi, > > I need to acquire the average of a matrix with n columns and m rows. > > For example, > 1 2 3 4 > 2 2 3 4 > 3 2 3 4 > > Is there any code to compute the average of the first 2 columns and last 2 columns separately as shown? > 1.5 3.5 > 2.0 3.5 > 2.5 3.5 > > Thank you.
Use proper indexing to select the input to MEAN:
A = [1 2 3 4 ; 2 2 3 4 ; 3 2 3 4] B = [mean(A(:,[1 2]),2) mean(A(:,[3 4]),2)]
See the help of MEAN to understand why it's second input is a 2.
~ Jos



