% [points]=datagen(sigma,inliers) % % This function generates 100 2D POINTS of which % INLIERS are normally distributed % with standard deviation SIGMA % around a randomly generated line % the remainder of the points are uniformly distributed in [-1,1]x[-1,1] function [points]=datagen(sigma,inliers); % generate random line a=randn(2,1); a=a/norm(a); b=rand(1)-0.5; % offset line=[a; b]; % line c=[a(2); -a(1)]; d=-a*b; % point closest to origin % generate points on line points=d*ones(1,inliers)+c*(2*rand(1,inliers)-1)+sigma*a*randn(1,inliers); points=[points rand(2,100-inliers)*2-1]; figure(1); clf; plot(points(1,1:inliers),points(2,1:inliers),'x'); hold on if (inliers<100) plot(points(1,inliers+1:100),points(2,inliers+1:100),'o'); end hold off; figure(2); clf; title('histogram of distance from line'); res=abs(line'*[points; ones(1,100)]); bar(0:0.1:1,histc(res,0:0.1:1));