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:
Zonally averaging data

Subject: Zonally averaging data

From: David

Date: 14 Mar, 2012 16:56:18

Message: 1 of 5

Hi,

I have a 3-D array of the size 100x110x456 (latitude x longitude x month), so each lat/long point corresponds with a value (of ocean surface heat flux).
I want to zonally average the array latitudinally so that I end up with one value per latitude which is the same for all longitudes...
So for example if i had the array:

x=[2 4 3;5 3 4;2 7 6]

x =

     2 4 3
     5 3 4
     2 7 6

I would want it to end up as this:

x =

     3 3 3
     4 4 4
     5 5 5

So the array doesn't lose shape but is averaged.

Thank you for any help.

Dave

Subject: Zonally averaging data

From: ImageAnalyst

Date: 14 Mar, 2012 17:42:01

Message: 2 of 5

Dave:
Not sure if it's the most compact way, but it works:

x=[2 4 3;5 3 4;2 7 6];

x3D = cat(3, x, x+1, x+2)
% Now we have our sample 3D matrix.


% Average along the column dimension
meanRowZ = mean(x3D, 2)

x3D_out = x3D;
for z = 1:size(x3D_out, 3)
for row = 1 : size(x3D_out, 3)
x3D_out(row, :, z) = meanRowZ(:,:,z);
end
end
x3D_out

Subject: Zonally averaging data

From: David

Date: 14 Mar, 2012 18:34:12

Message: 3 of 5

Thank you for your help,
I managed to create a code to do what I wanted after some attempts.
This is what I used:

for i=1:100;
    for j=1:110;
        for k=1:456;
            zone(i,j,k)=nanmean(anom(i,:,k).');
         end
    end
end

Dave

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c6866e15-1e69-4e78-bcf5-d3faf46dc65b@v7g2000yqb.googlegroups.com>...
> Dave:
> Not sure if it's the most compact way, but it works:
>
> x=[2 4 3;5 3 4;2 7 6];
>
> x3D = cat(3, x, x+1, x+2)
> % Now we have our sample 3D matrix.
>
>
> % Average along the column dimension
> meanRowZ = mean(x3D, 2)
>
> x3D_out = x3D;
> for z = 1:size(x3D_out, 3)
> for row = 1 : size(x3D_out, 3)
> x3D_out(row, :, z) = meanRowZ(:,:,z);
> end
> end
> x3D_out

Subject: Zonally averaging data

From: reza

Date: 15 Mar, 2012 03:50:12

Message: 4 of 5

On Mar 14, 2:34 pm, "David " <sum_is...@hotmail.com> wrote:
> Thank you for your help,
> I managed to create a code to do what I wanted after some attempts.
> This is what I used:
>
> for i=1:100;
>     for j=1:110;
>         for k=1:456;
>             zone(i,j,k)=nanmean(anom(i,:,k).');
>          end
>     end
> end
>
> Dave
>
>
>
>
>
>
>
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <c6866e15-1e69-4e78-bcf5-d3faf46dc...@v7g2000yqb.googlegroups.com>...
> > Dave:
> > Not sure if it's the most compact way, but it works:
>
> > x=[2 4 3;5 3 4;2 7 6];
>
> > x3D = cat(3, x, x+1, x+2)
> > % Now we have our sample 3D matrix.
>
> > % Average along the column dimension
> > meanRowZ = mean(x3D, 2)
>
> > x3D_out = x3D;
> > for z = 1:size(x3D_out, 3)
> >    for row = 1 : size(x3D_out, 3)
> >            x3D_out(row, :, z) = meanRowZ(:,:,z);
> >    end
> > end
> > x3D_out

Alternatively you can do this without loops:

zone = repmat(nanmean(anom,2), [1,size(anom,2),1]);

/reza

Subject: Zonally averaging data

From: ImageAnalyst

Date: 15 Mar, 2012 10:03:38

Message: 5 of 5

On Mar 14, 2:34 pm, "David " <sum_is...@hotmail.com> wrote:
>             zone(i,j,k)=nanmean(anom(i,:,k).');
---------------------------------------
What is nanmean? I don't have it. I assume if takes the mean without
nan's, which is something you can do with regular mean if you set up
your preferences that way. Anyway, you didn't say anything about
having nans in your data.

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