% Unit 4 (MATLAB Course @ UAM)
% (c) Alexander Knebe

%====================================
% Temperate comparison Madrid-London
%====================================
clear all, close all, clc

% define monthly averages (taken from www.wetter.com)
Tmad = [8.5, 11.0, 14.9, 18.4, 21.2, 26.9, 30.8, 29.5, 25.0, 18.5, 12.8, 8.8];
Tlon = [6.4 ,7.1, 10.1, 13.3, 16.9, 20.3, 21.8, 21.5, 18.5, 14.2, 10.1, 7.4];


% calculate some statistics for the whole data set
mean_Tmad = sum(Tmad)/length(Tmad),mean(Tmad)
mean_Tlon = sum(Tlon)/length(Tlon),mean(Tlon)

std_Tmad = sqrt(sum((Tmad-mean_Tmad).^2/(length(Tmad)-1))),std(Tmad)
std_Tlon = sqrt(sum((Tlon-mean_Tlon).^2/(length(Tlon)-1))),std(Tlon)


% bin data into four seasons
springMAD = Tmad([3 4 5]);     % spring = March, April, May
summerMAD = Tmad([6 7 8]);     % summer = June, July, August
autumMAD  = Tmad([9 10 11]);   % autumn = September, October, November
winterMAD = Tmad([12 1 2]);    % winter = December, January, February
Tmad_mean = [mean(springMAD), mean(summerMAD), mean(autumMAD), mean(winterMAD)];
Tmad_std  = [ std(springMAD),  std(summerMAD),  std(autumMAD),  std(winterMAD)];

springLON = Tlon([3 4 5]);
summerLON = Tlon([6 7 8]);
autumLON  = Tlon([9 10 11]);
winterLON = Tlon([12 1 2]);
Tlon_mean = [mean(springLON), mean(summerLON), mean(autumLON), mean(winterLON)];
Tlon_std  = [ std(springLON),  std(summerLON),  std(autumLON),  std(winterLON)];


% plot results
errorbar([1:4],Tmad_mean,Tmad_std,'r'), hold on
errorbar([1:4],Tlon_mean,Tlon_std,'b')

xlabel('season')
ylabel('temperature [C]')
title('average temperature per season')
legend('Madrid','London')



