Path: news.mathworks.com!not-for-mail
From: "ade77 " <ade100a@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: applying functions to grouped data
Date: Thu, 5 Nov 2009 19:09:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <hcv7sf$h4o$1@fred.mathworks.com>
References: <hcsqn1$ju4$1@fred.mathworks.com> <hct2gg$mm8$1@fred.mathworks.com> <hctf96$l7g$1@fred.mathworks.com> <hcthti$43u$1@fred.mathworks.com> <hcv3a6$ja$1@fred.mathworks.com>
Reply-To: "ade77 " <ade100a@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257448143 17560 172.30.248.37 (5 Nov 2009 19:09:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 5 Nov 2009 19:09:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1059495
Xref: news.mathworks.com comp.soft-sys.matlab:582836



> hello,
> i changed my data to separate the dates.  could you give me some tips on how to create a moving average filter?  i think it would be very useful for a variety of things in the future.
> thanks!

averages = filter(ones(1,2),2,data);

the equation you are solving indirectly is :
2y(n) = x(n) + x(n-1)
hence,
y(n) = (x(n) + x(n-1))/2

If you need to find the moving average of 3 previous, then it will be
averages = filter(ones(1,3),3,data);

for any case your data is the two columns of weights and Heigths.

    Note that for the first row, the moving average is (30 + 0)/2 = 15; etc
    anything before the first row is assumed zero, unless you want to specify your initial condition.
    
    If you want the output to be in a special formating,:
    and if your data if not confidential, you can click on my user name, and e mail the excel data to me or part of it to me, then I can properly reformat the excel file for you,and write the code for you.
    
    Note the reason I suggested you seperate the month,year and day is not only so that MATLAB can read the file easily, but also because, you can use the date functions in matlab to properly handle your situation.

If you need more help feel free to reply to this post.