Search All of the Math Forum:

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

Topic: matrix mean
Replies: 9   Last Post: Sep 11, 2013 5:13 PM

 Messages: [ Previous | Next ]
 dpb Posts: 9,289 Registered: 6/7/07
Re: matrix mean
Posted: Sep 10, 2013 9:03 AM

On 9/10/2013 4:41 AM, Puneet wrote:
> dpb <none@non.net> wrote in message <l0lbpf\$lel\$1@speranza.aioe.org>...
>> On 9/9/2013 6:40 AM, Puneet wrote:
>> > Hi - this is begginers question.
>> > I have a data set - 16 rows and 16 columns - I would like to average
>> > every 2 points to get an 8 rows 8 columns matrix.
>> >
>> > This is a learning phase so I can run something similar later for

>> larger
>> > data sets.
>> > Thanks.

>>
>> One way...(not necessarily the best :) ) presuming that the "every 2
>> points" means in both directions given the resulting size of output
>> for the described input. Similar works w/ filter() for the vector case.
>>
>> m4=filter2(ones(2)/4,z);
>> m4=m4(1:2:end,1:2:end);
>>
>> Hint: look up 2D convolution... :)
>>
>> accumarray() could be you friend amongst other ways to attack it...

...

> i would like to rephrase my query. if i have a row vector of length 16
> and i want to average every 2 consecutive elements and save it as a row
> vector, then how should i go about it. i know its a beginner query but
> may be its too specific as a really couldn't find it any where or even
> close to it.

Alternatively to filter()

n=length(z);
m2=accumarray([1:n]',[1:2:n]',[],@(i) mean(z(i:i+1)))';

--

Date Subject Author
9/9/13 Puneet
9/9/13 Curious
9/9/13 Curious
9/9/13 dpb
9/10/13 Puneet
9/10/13 Curious
9/10/13 dpb
9/10/13 dpb
9/10/13 Steven Lord
9/11/13 arich82