%% SVM on overlapping data 
 clear; clf; hold on

%% training vectors
 x=[10*(rand(100,2)-0.5);randn(100,2)];
 y=[zeros(100,1);ones(100,1)];
 plot3(x(1:100,1),x(1:100,2),2*ones(100,1),'x');
 plot3(x(101:200,1),x(101:200,2),2*ones(100,1),'o');
 model = svmtrain(y,x);
 
%% plotting decition surface
x=[];
for x1=-5:0.1:5
    for x2=-5:0.1:5
        x=[x;x1 x2];
    end
end
y=svmpredict(ones(10201,1),x,model);
y=reshape(y,101,101);
x=meshgrid(-5:0.1:5);
surf(x,x',y,'linestyle','none'); view(0,90);
cmap=[1 1 1; 0.9 0.9 0.9]; colormap(cmap);
axis square; box on;