Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Avergaing Matrix.
Replies: 1   Last Post: Feb 4, 2013 4:36 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Jos

Posts: 1,266
Registered: 10/24/08
Re: Avergaing Matrix.
Posted: Feb 4, 2013 4:36 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.