From: Alan Leung on
Hi,

Let say I have a matrix like this:

A = [1;2;3;4;5;6;7;8;9;10;11;12];

I would like to find out the average of every 6 elements such that it gives:

[3.5;9.5];

How can I do that?

Alan
From: TideMan on
On May 14, 9:14 am, "Alan Leung" <alan.le...(a)rogers.com> wrote:
> Hi,
>
> Let say I have a matrix like this:
>
> A = [1;2;3;4;5;6;7;8;9;10;11;12];
>
> I would like to find out the average of every 6 elements such that it gives:
>
> [3.5;9.5];
>
> How can I do that?
>
> Alan

help reshape
help mean
From: tinne123 on
Hi,

fancy you made a typo in the supposed results, but maybe this is what you wanted:

I = [ mean(A(1:6)); mean(A(7:10))]
I =

3.5000
8.5000

Good luck!
From: Alan on
Hi,

I was not clear in my previous message.

For A = [1;2;3;4;5;6;7;8;9;10;11;12]

B = [3.5;9.5;];

3.5 is the mean of 1,2,3,4,5,6.
9.5 is the mean of 7,8,9,10,11,12.

Let say I have a matrix that is 480000 x 1. I would like to have a matrix B such that B calculates the mean of every 6 elements (1~6,7~12,13~18,...,479995~480000). I am wondering how can I do that?

For the same situation, instead of mean let say I want to do Xth of percentile, how can I do that?

Alan






"tinne123 " <nastanova(a)yahoo.co.uk> wrote in message <hshs0o$amc$1(a)fred.mathworks.com>...
> Hi,
>
> fancy you made a typo in the supposed results, but maybe this is what you wanted:
>
> I = [ mean(A(1:6)); mean(A(7:10))]
> I =
>
> 3.5000
> 8.5000
>
> Good luck!
From: Walter Roberson on
Alan wrote:

> Let say I have a matrix that is 480000 x 1. I would like to have a
> matrix B such that B calculates the mean of every 6 elements
> (1~6,7~12,13~18,...,479995~480000). I am wondering how can I do that?

The previous response pointing you to reshape was appropriate.

mean(reshape(B, 6, SomethingGoesHere))


> For the same situation, instead of mean let say I want to do Xth of
> percentile, how can I do that?

It is probably fairly much alike the code you would use for finding that
percentile for a vector, only applied to the reshaped matrix.