%% Testing generalization perfroamnce of trained perceptron
 perceptronTrain;
 letterMatrix=rIn;
 for nflip = 1:80;    
    distH=[];
    for trial=1:10;     
       rIn=abs(letterMatrix-randomFlipMatrix(nflip));
       rOut=(wOut*rIn)>0.5;
       distH=[distH,sum(sum((rDes-rOut).^2))/26];
    end
    meanDistH(nflip)=mean(distH);
    stdDistH(nflip)=std(distH);
 end

 errorbar(1:80,meanDistH,stdDistH)
 xlabel('Number of flipped bits')
 ylabel('Average Hamming distance')