<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265012</link>
    <title>MATLAB Central Newsreader - applying functions to grouped data</title>
    <description>Feed for thread: applying functions to grouped data</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 04 Nov 2009 21:12:01 -0500</pubDate>
      <title>applying functions to grouped data</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265012#692192</link>
      <author>Anna Chen</author>
      <description>hello,&lt;br&gt;
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:&lt;br&gt;
&lt;br&gt;
Date  Height Weight&lt;br&gt;
1/31      30     20&lt;br&gt;
1/31      23     43&lt;br&gt;
1/31      20     50&lt;br&gt;
2/28      10     40&lt;br&gt;
2/28      40     30&lt;br&gt;
3/31      90     40&lt;br&gt;
3/31      10     30&lt;br&gt;
3/31      40     60&lt;br&gt;
&lt;br&gt;
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:&lt;br&gt;
&lt;br&gt;
Date  Rolling2-monthHeight   Rolling2-monthWeight&lt;br&gt;
2/28       24.6                            36.6&lt;br&gt;
3/31       38                               40&lt;br&gt;
&lt;br&gt;
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!</description>
    </item>
    <item>
      <pubDate>Wed, 04 Nov 2009 23:25:04 -0500</pubDate>
      <title>Re: applying functions to grouped data</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265012#692229</link>
      <author>ade77 </author>
      <description>you can use a moving average filter. Type doc filter.&lt;br&gt;
&lt;br&gt;
Also, if you can include the year with your date, then it will be more appropriate, and you can change it to a date number.&lt;br&gt;
&lt;br&gt;
Let me know if you need more help with the code.&lt;br&gt;
&lt;br&gt;
&amp;gt; Date  Height Weight&lt;br&gt;
&amp;gt; 1/31      30     20&lt;br&gt;
&amp;gt; 1/31      23     43&lt;br&gt;
&amp;gt; 1/31      20     50&lt;br&gt;
&amp;gt; 2/28      10     40&lt;br&gt;
&amp;gt; 2/28      40     30&lt;br&gt;
&amp;gt; 3/31      90     40&lt;br&gt;
&amp;gt; 3/31      10     30&lt;br&gt;
&amp;gt; 3/31      40     60&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Date  Rolling2-monthHeight   Rolling2-monthWeight&lt;br&gt;
&amp;gt; 2/28       24.6                            36.6&lt;br&gt;
&amp;gt; 3/31       38                               40&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
you can use a moving average filter. Type doc filter.&lt;br&gt;
&lt;br&gt;
Also, if you can include the year with your date, then it will be more appropriate, and you can change it to a date number.&lt;br&gt;
&lt;br&gt;
Let me know if you need more help with the code.</description>
    </item>
    <item>
      <pubDate>Thu, 05 Nov 2009 03:03:02 -0500</pubDate>
      <title>Re: applying functions to grouped data</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265012#692266</link>
      <author>Anna Chen</author>
      <description>thanks for your response!  actually, i'm having a problem even getting the dates in correctly to matlab.  i'm importing a large file that has dates in the first column, and matlab will always separate it from the rest of the columns.  how would i reincorporate this first column and apply the moving average filter?  also, what if i wanted to apply some other moving function, other than averages?&lt;br&gt;
&lt;br&gt;
thanks so much!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;ade77 &quot; &amp;lt;ade100a@gmail.com&amp;gt; wrote in message &amp;lt;hct2gg$mm8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; you can use a moving average filter. Type doc filter.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Also, if you can include the year with your date, then it will be more appropriate, and you can change it to a date number.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Let me know if you need more help with the code.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Date  Height Weight&lt;br&gt;
&amp;gt; &amp;gt; 1/31      30     20&lt;br&gt;
&amp;gt; &amp;gt; 1/31      23     43&lt;br&gt;
&amp;gt; &amp;gt; 1/31      20     50&lt;br&gt;
&amp;gt; &amp;gt; 2/28      10     40&lt;br&gt;
&amp;gt; &amp;gt; 2/28      40     30&lt;br&gt;
&amp;gt; &amp;gt; 3/31      90     40&lt;br&gt;
&amp;gt; &amp;gt; 3/31      10     30&lt;br&gt;
&amp;gt; &amp;gt; 3/31      40     60&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 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:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Date  Rolling2-monthHeight   Rolling2-monthWeight&lt;br&gt;
&amp;gt; &amp;gt; 2/28       24.6                            36.6&lt;br&gt;
&amp;gt; &amp;gt; 3/31       38                               40&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; you can use a moving average filter. Type doc filter.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Also, if you can include the year with your date, then it will be more appropriate, and you can change it to a date number.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Let me know if you need more help with the code.</description>
    </item>
    <item>
      <pubDate>Thu, 05 Nov 2009 03:48:02 -0500</pubDate>
      <title>Re: applying functions to grouped data</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265012#692276</link>
      <author>ade77 </author>
      <description>&lt;br&gt;
&amp;gt; thanks for your response!  actually, i'm having a problem even getting the dates in correctly to matlab.  i'm importing a large file that has dates in the first column, and matlab will always separate it from the rest of the columns.  how would i reincorporate this first column and apply the moving average filter?  also, what if i wanted to apply some other moving function, other than averages?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; thanks so much!&lt;br&gt;
&lt;br&gt;
First save your orignal file before manipulating it. then create another copy.&lt;br&gt;
&lt;br&gt;
Is your file an excel file? One easy way is to create ( in excel) three additional columns for year, month and day. I am not sure how good your excel is. &lt;br&gt;
&lt;br&gt;
The problem with excel is that when the date is in 'date format' in excel, MATLAB has problem recognizing that format.&lt;br&gt;
&lt;br&gt;
So once you import it into MATLAB, let me know. Actually, the actual code of your moving average is very easy to write.&lt;br&gt;
&lt;br&gt;
If you do not know how to create those columns in excel , let me know and I will give you the steps. Like new_col 1= YEAR(A1), new_col2 = MONTH(A1) etc</description>
    </item>
    <item>
      <pubDate>Thu, 05 Nov 2009 09:34:01 -0500</pubDate>
      <title>Re: applying functions to grouped data</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265012#692331</link>
      <author>Branko </author>
      <description>&quot;Anna Chen&quot; &amp;lt;icedredtea@yahoo.com&amp;gt; wrote in message &amp;lt;hcsqn1$ju4$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; hello,&lt;br&gt;
&amp;gt; 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:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Date  Height Weight&lt;br&gt;
&amp;gt; 1/31      30     20&lt;br&gt;
&amp;gt; 1/31      23     43&lt;br&gt;
&amp;gt; 1/31      20     50&lt;br&gt;
&amp;gt; 2/28      10     40&lt;br&gt;
&amp;gt; 2/28      40     30&lt;br&gt;
&amp;gt; 3/31      90     40&lt;br&gt;
&amp;gt; 3/31      10     30&lt;br&gt;
&amp;gt; 3/31      40     60&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Date  Rolling2-monthHeight   Rolling2-monthWeight&lt;br&gt;
&amp;gt; 2/28       24.6                            36.6&lt;br&gt;
&amp;gt; 3/31       38                               40&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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!&lt;br&gt;
&lt;br&gt;
Look at:&lt;br&gt;
datenum&lt;br&gt;
unique&lt;br&gt;
accumarray&lt;br&gt;
&lt;br&gt;
Branko</description>
    </item>
    <item>
      <pubDate>Thu, 05 Nov 2009 17:51:02 -0500</pubDate>
      <title>Re: applying functions to grouped data</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265012#692482</link>
      <author>Anna Chen</author>
      <description>hello,&lt;br&gt;
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.&lt;br&gt;
thanks!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;ade77 &quot; &amp;lt;ade100a@gmail.com&amp;gt; wrote in message &amp;lt;hcthti$43u$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; thanks for your response!  actually, i'm having a problem even getting the dates in correctly to matlab.  i'm importing a large file that has dates in the first column, and matlab will always separate it from the rest of the columns.  how would i reincorporate this first column and apply the moving average filter?  also, what if i wanted to apply some other moving function, other than averages?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; thanks so much!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; First save your orignal file before manipulating it. then create another copy.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is your file an excel file? One easy way is to create ( in excel) three additional columns for year, month and day. I am not sure how good your excel is. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The problem with excel is that when the date is in 'date format' in excel, MATLAB has problem recognizing that format.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So once you import it into MATLAB, let me know. Actually, the actual code of your moving average is very easy to write.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you do not know how to create those columns in excel , let me know and I will give you the steps. Like new_col 1= YEAR(A1), new_col2 = MONTH(A1) etc</description>
    </item>
    <item>
      <pubDate>Thu, 05 Nov 2009 19:09:03 -0500</pubDate>
      <title>Re: applying functions to grouped data</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265012#692505</link>
      <author>ade77 </author>
      <description>&lt;br&gt;
&amp;gt; hello,&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; thanks!&lt;br&gt;
&lt;br&gt;
averages = filter(ones(1,2),2,data);&lt;br&gt;
&lt;br&gt;
the equation you are solving indirectly is :&lt;br&gt;
2y(n) = x(n) + x(n-1)&lt;br&gt;
hence,&lt;br&gt;
y(n) = (x(n) + x(n-1))/2&lt;br&gt;
&lt;br&gt;
If you need to find the moving average of 3 previous, then it will be&lt;br&gt;
averages = filter(ones(1,3),3,data);&lt;br&gt;
&lt;br&gt;
for any case your data is the two columns of weights and Heigths.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Note that for the first row, the moving average is (30 + 0)/2 = 15; etc&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;anything before the first row is assumed zero, unless you want to specify your initial condition.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If you want the output to be in a special formating,:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;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.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;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.&lt;br&gt;
&lt;br&gt;
If you need more help feel free to reply to this post.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Fri, 06 Nov 2009 04:22:01 -0500</pubDate>
      <title>Re: applying functions to grouped data</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265012#692587</link>
      <author>Anna Chen</author>
      <description>thank you so much for your time!  it was very helpful!&lt;br&gt;
&lt;br&gt;
&quot;ade77 &quot; &amp;lt;ade100a@gmail.com&amp;gt; wrote in message &amp;lt;hcv7sf$h4o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; hello,&lt;br&gt;
&amp;gt; &amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt; thanks!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; averages = filter(ones(1,2),2,data);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; the equation you are solving indirectly is :&lt;br&gt;
&amp;gt; 2y(n) = x(n) + x(n-1)&lt;br&gt;
&amp;gt; hence,&lt;br&gt;
&amp;gt; y(n) = (x(n) + x(n-1))/2&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you need to find the moving average of 3 previous, then it will be&lt;br&gt;
&amp;gt; averages = filter(ones(1,3),3,data);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for any case your data is the two columns of weights and Heigths.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     Note that for the first row, the moving average is (30 + 0)/2 = 15; etc&lt;br&gt;
&amp;gt;     anything before the first row is assumed zero, unless you want to specify your initial condition.&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     If you want the output to be in a special formating,:&lt;br&gt;
&amp;gt;     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.&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you need more help feel free to reply to this post.&lt;br&gt;
&amp;gt;     </description>
    </item>
  </channel>
</rss>

