function lab8_example2

randn('state',0);

printq = 0;

close all

data1 = randn(50,2)/2 + 8;
data2 = randn(50,2)/2.3 + 10;
subplot(221)
plot_feats(data1,data2);
xlabel('Feature 1');
ylabel('Feature 2');


data3 = [randn(50,1)/2.3 + 10.6, randn(50,1)/2.1 + 10];
subplot(222)
plot_feats(data1,data3);
xlabel('Feature 1');
ylabel('Feature 2');


subplot(223);
data4 = randn(50,2)*[1 .3; .3 1.5] + repmat([16 20],[50 1]);
data5 = randn(50,2)*[1.2 -.2; -.2 .8] + repmat([20 15],[50 1]);
data6 = randn(50,2)*[.9 0; 0 1.1] + repmat([19 19.5],[50 1]);
data7 = randn(50,2)*[1 -.1; -.1 .6] + repmat([15 15],[50 1]);

hold on;
d = data4;
h = plot(d(:,1),d(:,2),'*b',mean(d(:,1)),mean(d(:,2)),'*k');
set(h(2),'LineWidth',2,'MarkerSize',16)

d = data5;
h = plot(d(:,1),d(:,2),'og',mean(d(:,1)),mean(d(:,2)),'ok');
set(h(2),'LineWidth',2,'MarkerSize',16)

d = data6;
h = plot(d(:,1),d(:,2),'+r',mean(d(:,1)),mean(d(:,2)),'+k');
set(h(2),'LineWidth',2,'MarkerSize',16)

d = data7;
h = plot(d(:,1),d(:,2),'sm',mean(d(:,1)),mean(d(:,2)),'sk');
set(h(2),'LineWidth',2,'MarkerSize',16)
hold off;
xlabel('Feature 1')
ylabel('Feature 2')


subplot(224);
data4 = randn(50,2)*[2 1; 1 2.5] + repmat([16 20],[50 1]);
data5 = randn(50,2)*[2.5 -1; -1 2] + repmat([20 15],[50 1]);
data6 = randn(50,2)*[2.5 0; 0 3] + repmat([19 19.5],[50 1]);
data7 = randn(50,2)*[1 -2; -2 1] + repmat([15 15],[50 1]);

hold on;
d = data4;
h = plot(d(:,1),d(:,2),'*b',mean(d(:,1)),mean(d(:,2)),'*k');
set(h(2),'LineWidth',2,'MarkerSize',16)

d = data5;
h = plot(d(:,1),d(:,2),'og',mean(d(:,1)),mean(d(:,2)),'ok');
set(h(2),'LineWidth',2,'MarkerSize',16)

d = data6;
h = plot(d(:,1),d(:,2),'+r',mean(d(:,1)),mean(d(:,2)),'+k');
set(h(2),'LineWidth',2,'MarkerSize',16)

hold off;
xlabel('Feature 1')
ylabel('Feature 2')


if printq
    print -depsc 'c:\documents and settings\mbartsch\my documents\eecs206\lab8\feat_examples'
end

function plot_feats(data1,data2)

mean1 = mean(data1);
mean2 = mean(data2);
plot(data1(:,1),data2(:,1),'go',data1(:,2),data2(:,2),'b*');
hold on;
h = plot(mean1(:,1),mean2(:,1),'ko',mean1(:,2),mean2(:,2),'k*');
set(h,'LineWidth',2,'MarkerSize',16)

slp = -diff(mean2)/diff(mean1);

if abs(slp) < 1 
    mx = max(data2(:));
    mn = min(data2(:));
    mid = [mean(mean1) mean(mean2)];
    h = line([mid(1)-(mid(2)-mn)*slp mid(1)+(mx-mid(2))*slp],[mn mx]);   
else
    mx = max(data1(:));
    mn = min(data1(:));
    mid = [mean(mean2) mean(mean1)];
    h = line([mn mx],[mid(1)-(mid(2)-mn)*1/slp mid(1)+(mx-mid(2))*1/slp]);   
end    
set(h,'Color',[0 0 0]);
axis equal