title: Generate new matrix from old matrix with specific conditions
body: <p>I have matrix <code>R(100*100)</code> and I want to generate new matrix <code>A(100*100)</code> as below conditions</p>
  
  <p>If I have a frequency to add a new condition<code>(let us say frequency = 20)</code>. This mean I will have five conditions inside my domain `(100/20)=5</p>
  
  <pre><code>From 1 to 20, from 21 to 40, from 41 to 60, from 61 to 80, and from 81 to 100.
  </code></pre>
  
  <p>Let us assume my original matrix is</p>
  
  <pre><code> [1 1 1……..1]
  
   [2 2 2 …….2]
  
   [3 3 3 ………3]
  
   And so on
  
  [100 100 100 …..100]
  </code></pre>
  
  <p>The new matrix must be</p>
  
  <pre><code>From 1 to 20 same as old matrix
  
  [1 1 1……..1]
  
  [2 2 2 …….2]
  
  [3 3 3………3]
  
  From 21 to 40
  
  A(21,j)=R(21,j)+R(1,j)   (row 21 + row 1)
  
  A(22,j)=R(22,j)+R(2,j)   (row 22 + row 2)
  
  A(23,j)=R(23,j)+R(3,j)   (row 23 + row 3)
  
  And so on
  
  From 41 to 60
  
  A(41,j)=R(41,j)+R(21,j) +R(1,j)  (row 41+row 21 + row 1)
  
  A(42,j)=R(42,j)+R(22,j) +R(2,j)  (row 42+row 22 + row 2)
  
  And so on
  A(81,j)=R(81,j)+R(61,j)+R(41,j)+R(21,j)+R(1,j)  (row 81+row 61 + row 41 + row 21+ row 1)
  </code></pre>
  
  <p>At each time that I reach to the frequency, I will have a new condition.
  My question is there any sufficient way to do that? I wrote my code and its work fine but each time I change frequency I will have a new condition. For the case above I have <code>5 conditions</code> but if I use <code>frequency 5</code> I will have <code>20 conditions</code> and I need to change all equations. I mean I need code to be able to handle any frequency</p>
  
  <p>I wrote below code</p>
  
  <pre><code>clc;
  clear;
  prompt = 'Enter Frequency=';       %Frequency=20
  N= input(prompt);
  Frequency=N;
  one_step=1/Frequency;              %Frequency
  time=Frequency*one_step;
  number_of_steps=time/one_step;     %Number of steps until next condition
  total_steps=100;
  R1 = rand(100,100);
  Number_of_Lines=(total_steps/number_of_steps)+1;  %100/20
  A(100,100)=0;
      for i=1:100
      for j=1:100
          if i&gt;=1 &amp;&amp; i&lt;=number_of_steps
              A(i,j)=R1(i,j);
          elseif i&gt;number_of_steps &amp;&amp; i&lt;= 2*number_of_steps
                  A(i,j)=R1(i,j)+R1(i-number_of_steps,j);
          elseif i&gt;2*number_of_steps &amp;&amp; i&lt;= 3*number_of_steps
                  A(i,j)=R1(i,j)+R1(i-number_of_steps,j)+R1(i-2*number_of_steps,j);
          elseif i&gt;3*number_of_steps &amp;&amp; i&lt;= 4*number_of_steps
                  A(i,j)=R1(i,j)+R1(i-number_of_steps,j)+R1(i-2*number_of_steps,j)...
                      +R1(i-3*number_of_steps,j);
          elseif i&gt;4*number_of_steps &amp;&amp; i&lt; 5*number_of_steps
                  A(i,j)=R1(i,j)+R1(i-number_of_steps,j)+R1(i-2*number_of_steps,j)...
                      +R1(i-3*number_of_steps,j)+R1(i-4*number_of_steps,j);
  
          end
  end
  
  end
  </code></pre>