title: how to get back to the first index of matrices
body: <p>I have to implement a single layer perceptron using Matlab.</p>
  
  <p>The problem which I am facing is that when I ran my program it gave me output for every input (it shows results 4 times), but I want to go back to the first index of matrix, after when it reached to the fourth, and I can't find out that how I get back to the first index of matrix. </p>
  
  <p>I want to train my program so that it yields the same result as in <code>b</code> by iterating the matrix in every loop.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>a = [ 1  1
        1 -1
       -1  1
       -1 -1 ];
  b = [1
      -1
      -1
      -1];
  disp(a);
  disp(b);
  x = a(:,1);
  disp(x);
  y = a(:,2);
  disp(y)
  learningrate = 0.1;
  maxiteration = 10;
  weight(1)=0.1;
  weight(2)=0.1;
  weight(3)=0.1;
  count = length(x);
  for p = 1:count
      s = (x(p) * weight(1))+ (y(p) * weight(2))+ weight(3);
      if s &gt;= 0
          result = 1;
          if result ~= b(p)
              weight(1) = weight(1)+learningrate*(b(p)-result)*x(p);
              weight(2) = weight(2)+learningrate*(b(p)-result)*y(p);
              weight(3) = weight(3)+learningrate*(b(p)-result);
              disp(result);
              disp(x(p));
              disp(y(p));
              disp(weight(1));
              disp(weight(2));
              disp(weight(3));
           end   
      else
          if s &lt;= 0
              result = -1;
              disp(result);
              if result ~= b(p)
                  weight(1)=weight(1)+learningrate*(b(p)-result)*x(p);
                  weight(2)=weight(2)+learningrate*(b(p)-result)*y(p);
                  weight(3)=weight(3)+learningrate*(b(p)-result);
                  disp(x(p));
                  disp(y(p));
                  disp(weight(1));
                  disp(weight(2));
                  disp(weight(3));
               end          
           end
       end
   end
  </code></pre>