clear
close all
clc
% Make sure you have previoulsy put the files into the desired folder

Data = load('chinese_data.txt'); % Load de Data from the ASCII file

% If you want, you can also load the data directly from the XLS file with:
[Databis TEXT] = xlsread('exercise_data.xls','Chinese Data','a3:h54');
for i=1:52,
    Province{i,1} = TEXT{i,1}; % Create the vector of province names
end

% Let's begin with the first task: analizing the data. 
Mean_2005 = mean(Data(:,[2 4 6])); % Mean of 2005 classifying by type of doll
Mean_2006 = mean(Data(:,[3 5 7])); % Mean of 2005 classifying by type of doll
% Now, show the results in a pie chart, both in the same figure (using the
% subplot command!)
figure(1),
subplot(2,1,1),pie3(Mean_2005,[1 0 0],{'A','B','C'}), title('2005 Sales','FontSize',12) %Denote the slice corresponding to the type A
subplot(2,1,2),pie3(Mean_2006,[1 0 0],{'A','B','C'}),title('2006 Sales','FontSize',12)
figure(2),
hist(Data(:,6)), % Plotting the histogram
set(gca,'FontSize',12) % To change the default font size
title('Type C: 2006 Sales','FontSize',14), % Title
% You can go on making interesesting graphs by your own

% Now, let's do some inference. Suppose you don't have information about
% all the provinces (perhaps because it is too expensive). We have a random
% sample of size 15 out of the 52 provinces. 
% The command randperm allows us to permutate randomly the numbers from 1 to
% 52. Then, once we have obtained the permutation, we just pick the
% arbitrarily the first (last, in the middle, or whatever you want) numbers
% you get:
g = randperm(52);
Sample = g(1:15); % Pick the first 15 
disp(Sample); % Show the code number of the selected provinces in the command window
disp(Province(Sample)) % Show the names of the selected provinces in the command window
figure(3), %Plot Type A of the selected provinces
H = bar(Data(Sample,2:3),1.1,'grouped');
axis tight, % To fit the axes to the max and min of the data
set(gca,'FontSize',8,'DefaultTextColor',[.5 0 .5],'xticklabel',Province(Sample,1)) % To change the default font size and color
title('Type A Sales','FontSize',14), % Title
legend('2005','2006'), % Legend
%Now, in order to check if the different types of dolls or the different
%years influences in the mean differences, we should perform an ANOVA
%(ANalysis Of VAriance).
% There exists a command in the Stat Toolbox called anova2 (type help
% anova2 to know how it works).
Table = [ [Data(Sample,2);Data(Sample,4);Data(Sample,6)],... % First column: the three 2005 sales, altogether
[Data(Sample,3);Data(Sample,5);Data(Sample,7)] ]; % Second column, the three 2006 sales.
anova2(Table,15) % The 15 is the number of reps (observations) in each 'cell' of the ANOVA Table
% Remember: In Colmuns, we check differences in the sales over 2005 and
% 2006; while in rows, we check differences in the sales of the three
% different dolls. We also check for interaction effects (by changing the
% year, the sales distribution of the types of dolls also varies.
% Get your own conclusions!

% END OF SCRIPT