%
% agepie.m - Read Input Data from Year1993-2014.xls (or Popu2014.xlsx)
%
Data=xlsread('Year1993-2014.xls','B2:W35');  % Read Input Data
row=22;  col=22;                             % rows = 1993~2014
A=Data(1:row,1:col);
Y=1993:2014;
subplot(2,2,1) 
% Y100=A(:,21); Y095=A(:,20)+A(:,21); Y090=A(:,19)+A(:,20)+A(:,21);
% plot(Y',Y100,'r-'); xlabel('Number of People over 100')
X=9:10:100;
B(1)=A(1,1)+A(1,2);   B(2)=A(1,3)+A(1,4);
B(3)=A(1,5)+A(1,6);   B(4)=A(1,7)+A(1,8);
B(5)=A(1,9)+A(1,10);  B(6)=A(1,11)+A(1,12);
B(7)=A(1,13)+A(1,14); B(8)=A(1,15)+A(1,16);
B(9)=A(1,17)+A(1,18);   B(10)=A(1,19)+A(1,20)+A(1,21);
C(1)=A(22,1)+A(22,2);   C(2)=A(22,3)+A(22,4);
C(3)=A(22,5)+A(22,6);   C(4)=A(22,7)+A(22,8);
C(5)=A(22,9)+A(22,10);  C(6)=A(22,11)+A(22,12);
C(7)=A(22,13)+A(22,14); C(8)=A(22,15)+A(22,16);
C(9)=A(22,17)+A(22,18);   C(10)=A(22,19)+A(22,20)+A(22,21);
bar(X',[B',C'],0.6); grid
legend('Year 1993','Year 2014','Location','NorthEast')
subplot(2,2,2)
Y085=+A(:,18)+A(:,19)+A(:,20)+A(:,21);
plot(Y',Y085,'r-'); xlabel('Number of Persons over 85')
subplot(2,2,3) 
Y065=A(:,14)+A(:,15)+A(:,16)+A(:,17)+A(:,18)+A(:,19)+A(:,20)+A(:,21);
plot(Y',Y065,'b-'); xlabel('Number of Persons over 65')
subplot(2,2,4) 
S=sum(A(22,1:col-1),2);                      % sum=A(22,22);
W20=A(22,1)+A(22,2)+A(22,3)+A(22,4);
W35=A(22,5)+A(22,6)+A(22,7);
W50=A(22,8)+A(22,9)+A(22,10);
W65=A(22,11)+A(22,12)+A(22,13);
W85=A(22,14)+A(22,15)+A(22,16)+A(22,17)+...
    A(22,18)+A(22,19)+A(22,20)+A(22,21);
W=[W20, W35, W50, W65, W85]/S
pie(W,{'20.46% in [0,20)', '22.07% in [20,35)', '24.00% in [35,50)',...
   '21.48% in [50,65)','11.99% over 65'})
title('Distribution of Taiwanese Residents in Age at the end of 2014')
