clear all;
%ylabels = ['1936'; '1972'; '2011'];
%ycells = cellstr(ylabels);
%ycells
%
%xlabels = ['Pensylvanicum'; 
%           'Rubrum       '; 
%	   'Saccharum    '];
%xcells = cellstr(xlabels);
%xcells
%
%A = [ 12 27 94; 22 40 52; 97 25 18 ];

[year Pen Rub Sac] = textread('Maple_Trees_Array.txt', '%s%d%d%d', 'headerlines', 1);
A = [Pen Rub Sac];
xcells = {'Pensylvanicum', 'Rubrum', 'Saccharum'};
ycells = year;

x = sum(A);
y = sum(A');
z = sum(x);
for i = 1:3
    A_row_norm(i,:) = A(i,:)/y(i);
end

figure(1);
bar(1:3, 100*A_row_norm);
set(gca, 'XTick', 1:3, 'XTickLabel', ycells);
legend(xcells);
xlabel({'','Year'});
ylabel({'Percent',''});
title('Figure 3.2');
bigger;

figure(2);
bar(1:3, 100*A_row_norm ,'stacked');
set(gca, 'XTick', 1:3, 'XTickLabel', ycells);
legend(xcells);
xlabel({'','Year'});
ylabel({'Percent',''});
title('Figure 3.3');
bigger;

figure(3);
z = [0 x(1:end-1)];
z = (x + z)/2;
for j=1:3
    bases = 0*eye(3);
    bases(j,j) = 1;
    bar(cumsum(z)/sum(x), bases*100*A_row_norm, 3.333*x(j)/sum(x), 'stacked');
    hold on;
end
hold off;
set(gca, 'XTick', cumsum(z)/sum(x), 'XTickLabel', ycells);
xlabel({'','Year'});
ylabel({'Percent',''});
title('Figure 3.4');
axis tight;
ylim([0 120]);
legend(xcells);
bigger;

%'Overall %'
%100*A/z
%
%'Col %'
%100*A*diag(x)^-1
%
%'Row %'
%100*diag(y)^-1*A
