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:
Annual averages

Subject: Annual averages

From: David

Date: 21 Feb, 2012 17:23:13

Message: 1 of 3

Hi,

I have the dataset:

anom = 100x110x456

100 and 110 relate to long/lat and 456 is months (so 38 years).

I need to get annual averages for the whole 38 years so i will end up with:

annual = 100x110x38

I need to use nanmean as there are many NaN values in the dataset.
I have a code to do the first year:

for i=1:100;
for j=1:110;
annual(i,j)=nanmean(i,j,1:12);
end
end

But can't figure out how to then to this for the rest of the years in one bit of coding.

Thanks for any help.

Subject: Annual averages

From: TideMan

Date: 21 Feb, 2012 18:55:03

Message: 2 of 3

On Feb 22, 6:23 am, "David " <sum_is...@hotmail.com> wrote:
> Hi,
>
> I have the dataset:
>
> anom = 100x110x456
>
> 100 and 110 relate to long/lat and 456 is months (so 38 years).
>
> I need to get annual averages for the whole 38 years so i will end up with:
>
> annual = 100x110x38
>
> I need to use nanmean as there are many NaN values in the dataset.
> I have a code to do the first year:
>
> for i=1:100;
> for j=1:110;
> annual(i,j)=nanmean(i,j,1:12);
> end
> end
>
> But can't figure out how to then to this for the rest of the years in one bit of coding.
>
> Thanks for any help.

% Move the data to the left
a1=permute(anom,[3 1 2]); % Now the shape is 456x100x110
% Separate out the years
a1=reshape(a1,12,38,100,110);
annual=squeeze(nanmean(a1));

Subject: Annual averages

From: David

Date: 22 Feb, 2012 16:34:12

Message: 3 of 3

TideMan <mulgor@gmail.com> wrote in message <295b3e13-9072-48be-b7c7-9a2bf9e10cb4@m24g2000yqb.googlegroups.com>...
> On Feb 22, 6:23 am, "David " <sum_is...@hotmail.com> wrote:
> > Hi,
> >
> > I have the dataset:
> >
> > anom = 100x110x456
> >
> > 100 and 110 relate to long/lat and 456 is months (so 38 years).
> >
> > I need to get annual averages for the whole 38 years so i will end up with:
> >
> > annual = 100x110x38
> >
> > I need to use nanmean as there are many NaN values in the dataset.
> > I have a code to do the first year:
> >
> > for i=1:100;
> > for j=1:110;
> > annual(i,j)=nanmean(i,j,1:12);
> > end
> > end
> >
> > But can't figure out how to then to this for the rest of the years in one bit of coding.
> >
> > Thanks for any help.
>
> % Move the data to the left
> a1=permute(anom,[3 1 2]); % Now the shape is 456x100x110
> % Separate out the years
> a1=reshape(a1,12,38,100,110);
> annual=squeeze(nanmean(a1));

Works perfectly mate thanks a lot I really appreciate it.

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