Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Averaging in 3rd dimension in a loop
Date: Fri, 15 Mar 2013 14:55:07 +0000 (UTC)
Organization: Erasmus MC
Lines: 21
Message-ID: <khvcoa$fa6$1@newscl01ah.mathworks.com>
References: <khv9h7$49f$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1363359307 15686 172.30.248.47 (15 Mar 2013 14:55:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 15 Mar 2013 14:55:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:791242

"Max" wrote in message <khv9h7$49f$1@newscl01ah.mathworks.com>...
> Dears, 
> 
> I want to take average of long data array in 3rd dimension, but I am not getting the wanted result. Lets say I have A = rand(8,8,10);  
> Now averaging (mean) over let say each 2 values in 3rd dimension, it should give me size 8x8x5. 
> 
> I did this, but doesn't work
> A1 = [];
> for m = 1: 2: 10
>     A1 = [A1; mean(A(:,:,m:m+4),3)];
> end
> 
> Any help in this regard would highly appreciated. Thanks 

You want to concatenate the averages in the third dimension (that is, making more planes in each loop):

A1 = cat(3,A1,mean(...,3)) 

[ x ; y  ] concatenates x and y in the 1st dimension (making more rows)

~ Jos