<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240993</link>
    <title>MATLAB Central Newsreader - obatining mean value for every fixed numbers of elements</title>
    <description>Feed for thread: obatining mean value for every fixed numbers of elements</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>Sun, 14 Dec 2008 09:50:03 -0500</pubDate>
      <title>obatining mean value for every fixed numbers of elements</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240993#616905</link>
      <author>Yihui Hung</author>
      <description>Hello, &lt;br&gt;
I have a 6X4 data set and need to average them across every 3X2 data point. The example is as follows:&lt;br&gt;
1, 2,3,4;     &lt;br&gt;
3, 4, 5,6;&lt;br&gt;
7, 8, 9,10;&lt;br&gt;
11, 12, 13, 14;&lt;br&gt;
15, 16,17,18; &lt;br&gt;
19,20,21 22; &lt;br&gt;
I would like to obtain four means from1,3,7,2,4,8;3,5,9,4,6,10;11,15,19,12,16,20;13,17,21,14,18,22. Are there some useful matlab function to do this? Any suggestion will appreciated.&lt;br&gt;
&lt;br&gt;
Sincerely,&lt;br&gt;
Yihui</description>
    </item>
    <item>
      <pubDate>Sun, 14 Dec 2008 15:42:02 -0500</pubDate>
      <title>Re: obatining mean value for every fixed numbers of elements</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240993#616954</link>
      <author>Johan Carlson</author>
      <description>&quot;Yihui Hung&quot; &amp;lt;a489930026@yahoo.com.tw&amp;gt; wrote in message &amp;lt;gi2ksb$qsa$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello, &lt;br&gt;
&amp;gt; I have a 6X4 data set and need to average them across every 3X2 data point. The example is as follows:&lt;br&gt;
&amp;gt; 1, 2,3,4;     &lt;br&gt;
&amp;gt; 3, 4, 5,6;&lt;br&gt;
&amp;gt; 7, 8, 9,10;&lt;br&gt;
&amp;gt; 11, 12, 13, 14;&lt;br&gt;
&amp;gt; 15, 16,17,18; &lt;br&gt;
&amp;gt; 19,20,21 22; &lt;br&gt;
&amp;gt; I would like to obtain four means from1,3,7,2,4,8;3,5,9,4,6,10;11,15,19,12,16,20;13,17,21,14,18,22. Are there some useful matlab function to do this? Any suggestion will appreciated.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Sincerely,&lt;br&gt;
&amp;gt; Yihui&lt;br&gt;
&lt;br&gt;
Here's one way of doing it:&lt;br&gt;
&lt;br&gt;
Create a 2D filter mask,&lt;br&gt;
H = ones(3,2)/6;&lt;br&gt;
&lt;br&gt;
Then filter your matrix (I called it X) with the &quot;moving average&quot;&lt;br&gt;
&lt;br&gt;
Y = conv2(H,X);&lt;br&gt;
&lt;br&gt;
You can now figure out which elements of Y are the ones you like and extract them.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
/JC</description>
    </item>
    <item>
      <pubDate>Mon, 15 Dec 2008 06:26:01 -0500</pubDate>
      <title>Re: obatining mean value for every fixed numbers of elements</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240993#617053</link>
      <author>Roger Stafford</author>
      <description>&quot;Yihui Hung&quot; &amp;lt;a489930026@yahoo.com.tw&amp;gt; wrote in message &amp;lt;gi2ksb$qsa$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello, &lt;br&gt;
&amp;gt; I have a 6X4 data set and need to average them across every 3X2 data point. The example is as follows:&lt;br&gt;
&amp;gt; 1, 2,3,4;     &lt;br&gt;
&amp;gt; 3, 4, 5,6;&lt;br&gt;
&amp;gt; 7, 8, 9,10;&lt;br&gt;
&amp;gt; 11, 12, 13, 14;&lt;br&gt;
&amp;gt; 15, 16,17,18; &lt;br&gt;
&amp;gt; 19,20,21 22; &lt;br&gt;
&amp;gt; I would like to obtain four means from1,3,7,2,4,8;3,5,9,4,6,10;11,15,19,12,16,20;13,17,21,14,18,22. Are there some useful matlab function to do this? Any suggestion will appreciated.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Sincerely,&lt;br&gt;
&amp;gt; Yihui&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Let A be your matrix and let the means be taken over p x q submatrices.  Then execute the following (mysterious) code:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;[M,N] = size(A);&lt;br&gt;
&amp;nbsp;m = M/p; n = N/q; % &amp;lt;-- m and n must evaluate to integers&lt;br&gt;
&amp;nbsp;[J,I] = meshgrid(p*(0:m*n-1)+m*p*(q-1)*floor((0:m*n-1)/m),...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(1:p*q)+(m-1)*p*floor((0:p*q-1)/p));&lt;br&gt;
&amp;nbsp;B = reshape(mean(reshape(A(I+J),p*q,m*n)),m,n);&lt;br&gt;
&lt;br&gt;
Matrix B will be the requested m x n matrix of mean values.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
  </channel>
</rss>

