Path: news.mathworks.com!not-for-mail
From: "Branko " <bogunovic@mbss.org>
Newsgroups: comp.soft-sys.matlab
Subject: Re: applying functions to grouped data
Date: Thu, 5 Nov 2009 09:34:01 +0000 (UTC)
Organization: National Institute of Biology
Lines: 28
Message-ID: <hcu669$5d0$1@fred.mathworks.com>
References: <hcsqn1$ju4$1@fred.mathworks.com>
Reply-To: "Branko " <bogunovic@mbss.org>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257413641 5536 172.30.248.38 (5 Nov 2009 09:34:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 5 Nov 2009 09:34:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 237386
Xref: news.mathworks.com comp.soft-sys.matlab:582662


"Anna Chen" <icedredtea@yahoo.com> wrote in message <hcsqn1$ju4$1@fred.mathworks.com>...
> hello,
> i'm a fairly inexperienced matlab user, and i had a question about applying functions to data based on certain groupings.  for example, let's say i have the following data set:
> 
> Date  Height Weight
> 1/31      30     20
> 1/31      23     43
> 1/31      20     50
> 2/28      10     40
> 2/28      40     30
> 3/31      90     40
> 3/31      10     30
> 3/31      40     60
> 
> i want to compute 2-month rolling averages of height and weight.  so on 2/28, i want the averages of heights on 1/31 and 2/28, and averages of weights on 1/31 and 2/28.  For 3/31, i want to do the same for 3/31 and 2/28.  I will end up with something like this:
> 
> Date  Rolling2-monthHeight   Rolling2-monthWeight
> 2/28       24.6                            36.6
> 3/31       38                               40
> 
> What would be the best way to do this?  I've been trying to use while loops, but the date format kind of messes that up.  Thanks so much for your help!

Look at:
datenum
unique
accumarray

Branko