Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Avergaing Matrix.

Subject: Avergaing Matrix.

From: Linus

Date: 4 Feb, 2013 02:41:08

Message: 1 of 2

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.

Subject: Avergaing Matrix.

From: Jos (10584)

Date: 4 Feb, 2013 09:36:08

Message: 2 of 2

"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

Tags for this Thread

No tags are associated with this thread.

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.

Contact us