% Example: [X,C1,C2,C3] = data_ex31_3(100,1,3,pi/6,pi/2.5,2.5*pi/3,6,19,28);
function [X,C1,C2,C3] = data_ex31_3(P,a,b,th1,th2,th3,st1,st2,st3)
R1 = [cos(th1) -sin(th1); sin(th1) cos(th1)];
R2 = [cos(th2) -sin(th2); sin(th2) cos(th2)];
R3 = [cos(th3) -sin(th3); sin(th3) cos(th3)];
a2 = a^2; b2 = b^2;
ku = 0;
X1 = [];
e = ones(1,100);
randn('state',st1)
while ku < P
    xw = 2*randn(2,1);
    x1 = xw(1)^2; x2 = xw(2)^2;
    if x1/a2 + x2/b2 <= 1
       X1 = [X1 xw];
       ku = ku + 1;
    end
end
X1 = R1*X1 + [0.8 0.7]'*e;
ku = 0;
X2 = [];
randn('state',st2)
while ku < P
    xw = 2*randn(2,1);
    x1 = xw(1)^2; x2 = xw(2)^2;
    if x1/a2 + x2/b2 <= 1
       X2 = [X2 xw];
       ku = ku + 1;
    end
end
X2 = R2*X2 + [2.8 2.9]'*e;
ku = 0;
X3 = [];
randn('state',st3)
while ku < P
    xw = 2*randn(2,1);
    x1 = xw(1)^2; x2 = xw(2)^2;
    if x1/a2 + x2/b2 <= 1
       X3 = [X3 xw];
       ku = ku + 1;
    end
end
X3 = R3*X3 + [-2.4 -2]'*e;
C1 = mean(X1,2); C2 = mean(X2,2); C3 = mean(X3,2);
X = [X1 X2 X3];
figure(1)
set(gca,'fontsize',14)
plot(X1(1,:),X1(2,:),'+k')
hold on
plot(X2(1,:),X2(2,:),'ok')
plot(X3(1,:),X3(2,:),'.k')
hold off
grid
axis([-5 6 -5 5])