function lab8_example

randn('state',0);

printq = 0;

close all
data = [randn(50,1), randn(50,1)];
data1 = [2*data(:,1) + 50, 2*data(:,2) + 40];

[h,x] = hist(data1,20);
h = bar(x,h,1,'stacked');
xlabel('Flower height (cm)');
ylabel('Number of flowers');
legend('Type A','Type B',0);
colormap([0 1 0; 0 0 1])

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

figure
data2 = [4*data(:,1) + 50, 4*data(:,2) + 44];

%subplot(121)
[h,x] = hist(data2,18);
h = bar(x,h,1);
xlabel('Flower height (cm)');
ylabel('Number of flowers');
legend('Type A','Type B',0);
colormap([0 1 0; 0 0 1])

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

figure
%subplot(122);

data3 = [(randn(50,1) + 1*data(:,1))*3 + 40, 46 + 3*(randn(50,1) + 1*data(:,2))];
%plot(data2(:,1),data3(:,1),'go',data2(:,2),data3(:,2),'b*')
plot_feats(data2,data3);
xlabel('Flower height (cm)');
ylabel('Leaf length (mm)');
legend('Type A','Type B',0);
axis equal

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

figure

data5 = [(randn(50,1) + 0*data(:,1))*3 + 44, 46+3*(randn(50,1) + 0*data(:,2))];

plot_feats(data2,data5);
xlabel('Flower height (inches)');
ylabel('Leaf length (inches)');
legend('Type A','Type B',0);
axis equal

if printq
    print -depsc 'c:\documents and settings\mbartsch\my documents\eecs206\lab8\hard_twofeat'
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