title: Implementing and ploting a perceptron in MATLAB
body: <p>I´m reviewing a code from <a href="http://www.cs.toronto.edu/~hinton/csc321/tutorialcode/perceptron.m" rel="noreferrer">Toronto perceptron MATLAB code</a></p>
  
  <p>The code is </p>
  
  <pre><code>function [w] = perceptron(X,Y,w_init)
  
  w = w_init;
  for iteration = 1 : 100  %&lt;- in practice, use some stopping criterion!
    for ii = 1 : size(X,2)         %cycle through training set
      if sign(w'*X(:,ii)) ~= Y(ii) %wrong decision?
        w = w + X(:,ii) * Y(ii);   %then add (or subtract) this point to w
      end
    end
    sum(sign(w'*X)~=Y)/size(X,2)   %show misclassification rate
  end
  </code></pre>
  
  <p>So I was reading how to apply this function to data matrix X, and target Y, but, do not know how to use this function, I understand, it returns a vector of weights, so it can classify.</p>
  
  <p>Could you please give an example, and explain it??</p>
  
  <p>I´ve tried</p>
  
  <pre><code>X=[0 0; 0 1; 1 1]
  Y=[1 0; 2 1]
  w=[1 1 1]
  Result = perceptron( X, Y, w )
  
  ??? Error using ==&gt; mtimes
  Inner matrix dimensions must agree.
  
  Error in ==&gt; perceptron at 15
              if sign(w'*X(:,ii)) ~= Y(ii) 
  
      Result = perceptron( X, Y, w' )
  
  ??? Error using ==&gt; ne
  Matrix dimensions must agree.
  
  Error in ==&gt; perceptron at 19
          sum(sign(w'*X)~=Y) / size(X,2);     
  </code></pre>
  
  <p>Thanks</p>
  
  <p>Thank you for the anwers, I got one more, If I change the Y = [0, 1], what happens to the algorithm?. </p>
  
  <p><strong>So, Any input data will not work with Y = [0,1] with this code of the perceptron right?,</strong> </p>
  
  <p><strong>-----------------------------EDIT------------------------</strong></p>
  
  <p>One more question, if I want to plot the <strong>line that divides the 2 classes</strong>, I know we can get that the line solving linear equation system that has to do with weights, but how, 
  what could I do?, I'm trying something like </p>
  
  <pre><code>% the initial weights
  w_init = [ 1 1 1]';  
  % the weights returned from perceptron    
  wtag   = perceptron(X,Y,w_init,15);
  
  % concatenate both
  Line = [wtag,w_init] 
  
  % solve the linear system, am I correct doing this?
  rref(Line')
  
  % plot???
  </code></pre>