Doug Schwarz <firstname.lastname@example.org> wrote in message <see-DE124D.email@example.com>... > In article > <firstname.lastname@example.org>, > TideMan <email@example.com> wrote: > > > On Apr 7, 12:10 pm, "Balachander Narasimhan" > > <balxxxxxch...@whatever.com> wrote: > > > Hi, > > > > > > I have a 3D array. If I need the mean of all elements in two dimensions of > > > this array, I can do something like > > > > > > mean(mean(a,1),2) to average over the first two dimensions of 3D array a > > > lets say of size 5x5x5 > > > > > > But I cannot do the same for variance. One of the options seems to be > > > > > > for k =1:5 > > > b = a(:,:,k); > > > v(k) = var(reshape(b,25,1)) > > > end > > > > > > Is there a way to avoid this loop? > > > > You can do the same with var, only the dimension is the third > > argument, not the second: > > var(var(a,0,1),0,2) > > No, the mean of the mean is the mean of the whole matrix, but the > variance of the variance is not the variance of the whole matrix. > > To the OP: > > a = rand(l,m,n); > v = var(reshape(a,,n)); > > -- > Doug Schwarz > dmschwarz&ieee,org > Make obvious changes to get real email address.