clear all;
close all;
clc;

%% Import data from text file.
% Script for importing data from the following text file:
%
%    C:\Users\Owner\Documents\MATLAB\Models II\Cincinnati.csv
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.

% Auto-generated by MATLAB on 2015/02/25 10:56:19

%% Initialize variables.
filename = 'C:\Users\Owner\Documents\MATLAB\Models II\Cincinnati.csv';
delimiter = ',';
startRow = 2;

%% Format string for each line of text:
%   column1: text (%s)
%	column2: double (%f)
%   column3: double (%f)
%	column4: double (%f)
%   column5: double (%f)
%	column6: double (%f)
%   column7: double (%f)
%	column8: double (%f)
%   column9: double (%f)
%	column10: double (%f)
%   column11: double (%f)
%	column12: double (%f)
%   column13: double (%f)
%	column14: double (%f)
%   column15: double (%f)
%	column16: double (%f)
%   column17: double (%f)
%	column18: double (%f)
%   column19: double (%f)
%	column20: double (%f)
%   column21: double (%f)
%	column22: double (%f)
%   column23: double (%f)
%	column24: double (%f)
%   column25: double (%f)
%	column26: double (%f)
%   column27: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%s%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%[^\n\r]';

%% Open the text file.
fileID = fopen(filename,'r');

%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines' ,startRow-1, 'ReturnOnError', false);

%% Close the text file.
fclose(fileID);

%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.

%% Allocate imported array to column variable names
DATE1 = dataArray{:, 1};
HLYCLDHNORMAL1 = dataArray{:, 2};
HLYHTDHNORMAL1 = dataArray{:, 3};
HLYPRES10PCTL1 = dataArray{:, 4};
HLYPRES90PCTL1 = dataArray{:, 5};
HLYPRESNORMAL1 = dataArray{:, 6};
HLYCLODPCTBKN1 = dataArray{:, 7};
HLYCLODPCTCLR1 = dataArray{:, 8};
HLYCLODPCTFEW1 = dataArray{:, 9};
HLYCLODPCTOVC1 = dataArray{:, 10};
HLYCLODPCTSCT1 = dataArray{:, 11};
HLYDEWP10PCTL1 = dataArray{:, 12};
HLYDEWP90PCTL1 = dataArray{:, 13};
HLYDEWPNORMAL1 = dataArray{:, 14};
HLYHIDXNORMAL1 = dataArray{:, 15};
HLYTEMP10PCTL1 = dataArray{:, 16};
HLYTEMP90PCTL1 = dataArray{:, 17};
HLYTEMPNORMAL1 = dataArray{:, 18};
HLYWCHLNORMAL1 = dataArray{:, 19};
HLYWINDAVGSPD1 = dataArray{:, 20};
HLYWINDVCTDIR1 = dataArray{:, 21};
HLYWINDVCTSPD1 = dataArray{:, 22};
HLYWINDPCTCLM1 = dataArray{:, 23};
HLYWIND1STDIR1 = dataArray{:, 24};
HLYWIND1STPCT1 = dataArray{:, 25};
HLYWIND2NDDIR1 = dataArray{:, 26};
HLYWIND2NDPCT1 = dataArray{:, 27};

%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;

%% Import data from text file.
% Script for importing data from the following text file:
%
%    C:\Users\Owner\Documents\MATLAB\Models II\Louisville.csv
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.

% Auto-generated by MATLAB on 2015/02/25 10:57:11

%% Initialize variables.
filename = 'C:\Users\Owner\Documents\MATLAB\Models II\Louisville.csv';
delimiter = ',';
startRow = 2;

%% Format string for each line of text:
%   column1: text (%s)
%	column2: double (%f)
%   column3: double (%f)
%	column4: double (%f)
%   column5: double (%f)
%	column6: double (%f)
%   column7: double (%f)
%	column8: double (%f)
%   column9: double (%f)
%	column10: double (%f)
%   column11: double (%f)
%	column12: double (%f)
%   column13: double (%f)
%	column14: double (%f)
%   column15: double (%f)
%	column16: double (%f)
%   column17: double (%f)
%	column18: double (%f)
%   column19: double (%f)
%	column20: double (%f)
%   column21: double (%f)
%	column22: double (%f)
%   column23: double (%f)
%	column24: double (%f)
%   column25: double (%f)
%	column26: double (%f)
%   column27: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%s%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%[^\n\r]';

%% Open the text file.
fileID = fopen(filename,'r');

%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines' ,startRow-1, 'ReturnOnError', false);

%% Close the text file.
fclose(fileID);

%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.

%% Allocate imported array to column variable names
DATE = dataArray{:, 1};
HLYCLDHNORMAL = dataArray{:, 2};
HLYHTDHNORMAL = dataArray{:, 3};
HLYPRES10PCTL = dataArray{:, 4};
HLYPRES90PCTL = dataArray{:, 5};
HLYPRESNORMAL = dataArray{:, 6};
HLYCLODPCTBKN = dataArray{:, 7};
HLYCLODPCTCLR = dataArray{:, 8};
HLYCLODPCTFEW = dataArray{:, 9};
HLYCLODPCTOVC = dataArray{:, 10};
HLYCLODPCTSCT = dataArray{:, 11};
HLYDEWP10PCTL = dataArray{:, 12};
HLYDEWP90PCTL = dataArray{:, 13};
HLYDEWPNORMAL = dataArray{:, 14};
HLYHIDXNORMAL = dataArray{:, 15};
HLYTEMP10PCTL = dataArray{:, 16};
HLYTEMP90PCTL = dataArray{:, 17};
HLYTEMPNORMAL = dataArray{:, 18};
HLYWCHLNORMAL = dataArray{:, 19};
HLYWINDAVGSPD = dataArray{:, 20};
HLYWINDVCTDIR = dataArray{:, 21};
HLYWINDVCTSPD = dataArray{:, 22};
HLYWINDPCTCLM = dataArray{:, 23};
HLYWIND1STDIR = dataArray{:, 24};
HLYWIND1STPCT = dataArray{:, 25};
HLYWIND2NDDIR = dataArray{:, 26};
HLYWIND2NDPCT = dataArray{:, 27};

%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;

%% Import data from text file.
% Script for importing data from the following text file:
%
%    C:\Users\Owner\Documents\MATLAB\Models II\491660.csv
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.

% Auto-generated by MATLAB on 2015/03/05 08:43:10

%% Initialize variables.
filename = 'C:\Users\Owner\Documents\MATLAB\Models II\491660.csv';
delimiter = '';
startRow = 2;

%% Format string for each line of text:
%   column1: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%f%[^\n\r]';

%% Open the text file.
fileID = fopen(filename,'r');

%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines' ,startRow-1, 'ReturnOnError', false);

%% Close the text file.
fclose(fileID);

%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.

%% Allocate imported array to column variable names
HPCP = dataArray{:, 1};

%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;

%% 

% Normal1 = Cincinnati
% Normal = Louisville

load Weather;

Sea_Level_Pressure_Mean_C = 0.1*HLYPRESNORMAL1; %1
Sea_Level_Pressure_Mean_L = 0.1*HLYPRESNORMAL;
Clouds_Broken_Percentage_C = 0.1*HLYCLODPCTBKN1; %2
Clouds_Broken_Percentage_L = 0.1*HLYCLODPCTBKN;
Dew_Point_90th_Percentile_C = 0.1*HLYDEWP90PCTL1; %3
Dew_Point_90th_Percentile_L = 0.1*HLYDEWP90PCTL;
Secondary_Wind_Direction_C = HLYWIND2NDDIR1; %4
Secondary_Wind_Direction_L = HLYWIND2NDDIR;
Prevailing_Wind_Percentage_C = 0.1*HLYWIND1STPCT1; %5
Prevailing_Wind_Percentage_L = 0.1*HLYWIND1STPCT;
Dew_Point_Mean_C = 0.1*HLYDEWPNORMAL1; %6
Dew_Point_Mean_L = 0.1*HLYDEWPNORMAL;
Cooling_Degree_Hours_C = HLYCLDHNORMAL1; %7
Cooling_Degree_Hours_L = HLYCLDHNORMAL;
Sea_Level_Pressure_10th_Percentile_C = 0.1*HLYPRES10PCTL1; %8
Sea_Level_Pressure_10th_Percentile_L = 0.1*HLYPRES10PCTL;
Mean_Wind_Vector_Magnitude_C = 0.1*HLYWINDVCTSPD1; %9
Mean_Wind_Vector_Magnitude_L = 0.1*HLYWINDVCTSPD;
Prevailing_Wind_Direction_C = HLYWIND1STDIR1; %10
Prevailing_Wind_Direction_L = HLYWIND1STDIR;
Temperature_90th_Percentile_C = 0.1*HLYTEMP90PCTL1; %11
Temperature_90th_Percentile_L = 0.1*HLYTEMP90PCTL;
Heating_Degree_Hours_C = HLYHTDHNORMAL1; %12
Heating_Degree_Hours_L = HLYHTDHNORMAL;
Average_Wind_Speed_C = 0.1*HLYWINDAVGSPD1; %13
Average_Wind_Speed_L = 0.1*HLYWINDAVGSPD;
Mean_Wind_Vector_Direction_C = HLYWINDVCTDIR1; %14
Mean_Wind_Vector_Direction_L = HLYWINDVCTDIR;
Temperature_10th_Percentile_C = 0.1*HLYTEMP10PCTL1; %15
Temperature_10th_Percentile_L = 0.1*HLYTEMP10PCTL;
Heat_Index_Mean_C = 0.1*HLYHIDXNORMAL1; %16
Heat_Index_Mean_L = 0.1*HLYHIDXNORMAL;
Secondary_Wind_Percentage_C = 0.1*HLYWIND2NDPCT1; %17
Secondary_Wind_Percentage_L = 0.1*HLYWIND2NDPCT;
Clouds_Scattered_Percentage_C = 0.1*HLYCLODPCTSCT1; %18
Clouds_Scattered_Percentage_L = 0.1*HLYCLODPCTSCT;
Percentage_Calm_C = 0.1*HLYWINDPCTCLM1; %19
Percentage_Calm_L = 0.1*HLYWINDPCTCLM;
Temperature_Mean_C = 0.1*HLYTEMPNORMAL1; %20
Temperature_Mean_L = 0.1*HLYTEMPNORMAL;
Wind_Chill_Mean_C = 0.1*HLYWCHLNORMAL1; %21
Wind_Chill_Mean_L = 0.1*HLYWCHLNORMAL;
Sea_Level_Pressure_90th_Percentile_C = 0.1*HLYPRES90PCTL1; %22
Sea_Level_Pressure_90th_Percentile_L = 0.1*HLYPRES90PCTL;
Clouds_Few_Percentage_C = 0.1*HLYCLODPCTFEW1; %23
Clouds_Few_Percentage_L = 0.1*HLYCLODPCTFEW;
Dew_Point_10th_Percentile_C = 0.1*HLYDEWP10PCTL1; %24
Dew_Point_10th_Percentile_L = 0.1*HLYDEWP10PCTL;
Clouds_Overcast_Percentage_C = 0.1*HLYCLODPCTOVC1; %25
Clouds_Overcast_Percentage_L = 0.1*HLYCLODPCTOVC;
Clouds_Clear_Percentage_C = 0.1*HLYCLODPCTCLR1; %26
Clouds_Clear_Percentage_L = 0.1*HLYCLODPCTCLR;
%Humidity/DewPoint
%Temperature
%Precipitation

for i = 1:length(Clouds_Few_Percentage_C)
    if Cooling_Degree_Hours_C(i) == -7777
        Cooling_Degree_Hours_C(i) = 0;
    end
    if Cooling_Degree_Hours_L(i) == -7777
        Cooling_Degree_Hours_L(i) = 0;
    end
    if Heating_Degree_Hours_C(i) == -7777
        Heating_Degree_Hours_C(i) = 0;
    end
    if Heating_Degree_Hours_L(i) == -7777
        Heating_Degree_Hours_L(i) = 0;
    end
    
end

Cooling_Degree_Hours_C = 0.1*Cooling_Degree_Hours_C;
Cooling_Degree_Hours_L = 0.1*Cooling_Degree_Hours_L;
Heating_Degree_Hours_C = 0.1*Heating_Degree_Hours_C;
Heating_Degree_Hours_L = 0.1*Heating_Degree_Hours_L;

newArray = zeros(364,24);
newArray2 = zeros(364,24);
MinC = zeros(364,24);
MinL = MinC;
MaxC = MinC;
MaxL = MinC;
counter = 1;
for row = 1:364
    for col = 1:24
        newArray(row,col) = Temperature_90th_Percentile_C(counter);
        newArray2(row,col) = Temperature_90th_Percentile_L(counter);
        MinC(row,col) = Temperature_10th_Percentile_C(counter);
        MinL(row,col) = Temperature_10th_Percentile_L(counter);
        MaxC(row,col) = Temperature_90th_Percentile_C(counter);
        MaxL(row,col) = Temperature_90th_Percentile_L(counter);
        counter = counter + 1;
    end
end

figure;
plot(1:24,MinC(1:30,:),1:24,MaxC(1:30,:))

figure;

DailyMax = W.TMAX;
DailyMin = W.TMIN;
DailyCounter = 1;

for row = 1:364
    newArray(row,:) = 1/abs(max(newArray(row,:)))*newArray(row,:);
    newArray(row,:) = DailyMax(DailyCounter)*newArray(row,:);
    MaxC(row,:) = 1/abs(max(MaxC(row,:)))*MaxC(row,:);
    MaxC(row,:) = DailyMax(DailyCounter)*MaxC(row,:);
    DailyCounter = DailyCounter + 1;
end




% figure;
% for i = 1:364
%     plot(1:24,newArray(i,:),1:24,newArray2(i,:));
%     ylim([25 90]);
%     pause(0.1);
% end
degree = 10;
Deriv1 = zeros(364,24);
Deriv2 = zeros(364,24);
%Derivative
for row = 1:364
    for col = 1:24
        if row == 1 && col == 1
            Deriv1(row,col) = -0.4;
        elseif col == 1
            Deriv1(row,col) = newArray(row,col)-newArray(row-1,24);
        else
        Deriv1(row,col) = newArray(row,col)-newArray(row,col-1);
        Deriv2(row,col) = newArray2(row,col)-newArray2(row,col-1);
        end
    end
end
time = 1:0.01:24;

JanuaryC = Deriv1(1:31,:);
% JanuaryC(:,1) = -0.4;
JanuaryL = Deriv2(1:31,:);
% JanuaryL(:,1) = -0.4;

fitJC = 0;
fitJL = 0;
for i = 1:length(JanuaryC(:,1))
    fitJC = fitJC + polyfit(1:24,JanuaryC(i,:),degree);
    fitJL = fitJL + polyfit(1:24,JanuaryL(i,:),degree);
end
fitJC = fitJC/length(JanuaryC(:,1));
fitJL = fitJL/length(JanuaryL(:,1));

FebruaryC = Deriv1(32:59,:);
FebruaryL = Deriv2(32:59,:);

fitFC = 0;
fitFL = 0;
for i = 1:length(FebruaryC(:,1))
    fitFC = fitFC + polyfit(1:24,FebruaryC(i,:),degree);
    fitFL = fitFL + polyfit(1:24,FebruaryL(i,:),degree);
end
fitFC = fitFC/length(FebruaryC(:,1));
fitFL = fitFL/length(FebruaryL(:,1));

MarchC = Deriv1(60:90,:);
MarchL = Deriv2(60:90,:);

fitMhC = 0;
fitMhL = 0;
for i = 1:length(MarchC(:,1))
    fitMhC = fitMhC + polyfit(1:24,MarchC(i,:),degree);
    fitMhL = fitMhL + polyfit(1:24,MarchL(i,:),degree);
end
fitMhC = fitMhC/length(MarchC(:,1));
fitMhL = fitMhL/length(MarchL(:,1));

AprilC = Deriv1(91:120,:);
AprilL = Deriv2(91:120,:);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fitAC = 0;
fitAL = 0;
for i = 1:length(AprilC(:,1))
    fitAC = fitAC + polyfit(1:24,AprilC(i,:),degree);
    fitAL = fitAL + polyfit(1:24,AprilL(i,:),degree);
end
fitAC = fitAC/length(AprilC(:,1));
fitAL = fitAL/length(AprilL(:,1));

MayC = Deriv1(121:151,:);
MayL = Deriv2(121:151,:);

fitMyC = 0;
fitMyL = 0;
for i = 1:length(MayC(:,1))
    fitMyC = fitMyC + polyfit(1:24,MayC(i,:),degree);
    fitMyL = fitMyL + polyfit(1:24,MayL(i,:),degree);
end
fitMyC = fitMyC/length(MayC(:,1));
fitMyL = fitMyL/length(MayL(:,1));

JuneC = Deriv1(152:181,:);
JuneL = Deriv2(152:181,:);

fitJnC = 0;
fitJnL = 0;
for i = 1:length(JuneC(:,1))
    fitJnC = fitJnC + polyfit(1:24,JuneC(i,:),degree);
    fitJnL = fitJnL + polyfit(1:24,JuneL(i,:),degree);
end
fitJnC = fitJnC/length(JuneC(:,1));
fitJnL = fitJnL/length(JuneL(:,1));

JulyC = Deriv1(182:212,:);
JulyL = Deriv2(182:212,:);

fitJyC = 0;
fitJyL = 0;
for i = 1:length(JulyC(:,1))
    fitJyC = fitJyC + polyfit(1:24,JulyC(i,:),degree);
    fitJyL = fitJyL + polyfit(1:24,JulyL(i,:),degree);
end
fitJyC = fitJyC/length(JulyC(:,1));
fitJyL = fitJyL/length(JulyL(:,1));

AugustC = Deriv1(213:243,:);
AugustL = Deriv2(213:243,:);

fitAuC = 0;
fitAuL = 0;
for i = 1:length(AugustC(:,1))
    fitAuC = fitAuC + polyfit(1:24,AugustC(i,:),degree);
    fitAuL = fitAuL + polyfit(1:24,AugustL(i,:),degree);
end
fitAuC = fitAuC/length(AugustC(:,1));
fitAuL = fitAuL/length(AugustL(:,1));

SeptemberC = Deriv1(244:273,:);
SeptemberL = Deriv2(244:273,:);

fitSC = 0;
fitSL = 0;
for i = 1:length(SeptemberC(:,1))
    fitSC = fitSC + polyfit(1:24,SeptemberC(i,:),degree);
    fitSL = fitSL + polyfit(1:24,SeptemberL(i,:),degree);
end
fitSC = fitSC/length(SeptemberC(:,1));
fitSL = fitSL/length(SeptemberL(:,1));

OctoberC = Deriv1(274:304,:);
OctoberL = Deriv2(274:304,:);

fitOC = 0;
fitOL = 0;
for i = 1:length(OctoberC(:,1))
    fitOC = fitOC + polyfit(1:24,OctoberC(i,:),degree);
    fitOL = fitOL + polyfit(1:24,OctoberL(i,:),degree);
end
fitOC = fitOC/length(OctoberC(:,1));
fitOL = fitOL/length(OctoberL(:,1));

NovemberC = Deriv1(305:334,:);
NovemberL = Deriv2(305:334,:);

fitNC = 0;
fitNL = 0;
for i = 1:length(NovemberC(:,1))
    fitNC = fitNC + polyfit(1:24,NovemberC(i,:),degree);
    fitNL = fitNL + polyfit(1:24,NovemberL(i,:),degree);
end
fitNC = fitNC/length(NovemberC(:,1));
fitNL = fitNL/length(NovemberL(:,1));

DecemberC = Deriv1(335:364,:);
DecemberL = Deriv2(335:364,:);

fitDC = 0;
fitDL = 0;
for i = 1:length(DecemberC(:,1))
    fitDC = fitDC + polyfit(1:24,DecemberC(i,:),degree);
    fitDL = fitDL + polyfit(1:24,DecemberL(i,:),degree);
end
fitDC = fitDC/length(DecemberC(:,1));
fitDL = fitDL/length(DecemberL(:,1));


for i = 1:length(JanuaryC(1:28,1))
    subplot(3,4,1);
    plot(1:24,JanuaryC(i,:),1:24,JanuaryL(i,:),time,polyval(fitJC,time),time,polyval(fitJL,time));
    ylim([-4 4]);
    title('January');
    subplot(3,4,2)
    plot(1:24,FebruaryC(i,:),1:24,FebruaryL(i,:),time,polyval(fitFC,time),time,polyval(fitFL,time));
    ylim([-4 4]);
    title('February');
    subplot(3,4,3);
    plot(1:24,MarchC(i,:),1:24,MarchL(i,:),time,polyval(fitMhC,time),time,polyval(fitMhL,time));
    ylim([-4 4]);
    title('March');
    subplot(3,4,4);
    plot(1:24,AprilC(i,:),1:24,AprilL(i,:),time,polyval(fitAC,time),time,polyval(fitAL,time));
    ylim([-4 4]);
    title('April');
    subplot(3,4,5);
    plot(1:24,MayC(i,:),1:24,MayL(i,:),time,polyval(fitMyC,time),time,polyval(fitMyL,time));
    ylim([-4 4]);
    title('May');
    subplot(3,4,6);
    plot(1:24,JuneC(i,:),1:24,JuneL(i,:),time,polyval(fitJnC,time),time,polyval(fitJnL,time));
    ylim([-4 4]);
    title('June');
    subplot(3,4,7);
    plot(1:24,JulyC(i,:),1:24,JulyL(i,:),time,polyval(fitJyC,time),time,polyval(fitJyL,time));
    ylim([-4 4]);
    title('July');
    subplot(3,4,8);
    plot(1:24,AugustC(i,:),1:24,AugustL(i,:),time,polyval(fitAuC,time),time,polyval(fitAuL,time));
    ylim([-4 4]);
    title('August');
    subplot(3,4,9);
    plot(1:24,SeptemberC(i,:),1:24,SeptemberL(i,:),time,polyval(fitSC,time),time,polyval(fitSL,time));
    ylim([-4 4]);
    title('September');
    subplot(3,4,10);
    plot(1:24,OctoberC(i,:),1:24,OctoberL(i,:),time,polyval(fitOC,time),time,polyval(fitOL,time));
    ylim([-4 4]);
    title('October');
    subplot(3,4,11);
    plot(1:24,NovemberC(i,:),1:24,NovemberL(i,:),time,polyval(fitNC,time),time,polyval(fitNL,time));
    ylim([-4 4]);
    title('November');
    subplot(3,4,12);
    plot(1:24,DecemberC(i,:),1:24,DecemberL(i,:),time,polyval(fitDC,time),time,polyval(fitDL,time));
    ylim([-4 4]);
    title('December');
    pause(0.1);
end

% 
% eqJC = polyval(fitJC,time);
% eqJL = polyval(fitJL,time);
% 
% intJC(1) = 0;
% intJL(1) = 0;
% for k = 2:length(time)
%     intJC(k) = intJC(k-1) + (eqJC(k) + eqJC(k-1))/2*0.01;
%     intJL(k) = intJL(k-1) + (eqJL(k) + eqJL(k-1))/2*0.01;
% end


%plot(1:length(MaxC),MaxC,1:length(MinC),MinC);

% for hour = 1:24
%     firstDays(:,hour) = Temperature_Mean_C(hour:24:31*24);
% end
% 
plot(1:24,MaxC(1,:));
for day = 1:364
    fitMaxC = polyfit(1:24,MaxC(day,:),degree);
    fitMinC = polyfit(1:24,MinC(day,:),degree);
    filledMax = polyval(fitMaxC,time);
    filledMin = polyval(fitMinC,time);
    POLY(day) = {filledMax};
    POLY2(day) = {filledMin};
    filledMax = 1/abs(max(filledMax))*filledMax;
    filledMax = DailyMax(day)*filledMax;
end

POLY2 = POLY2';
POLY = POLY';

for day = 1:length(POLY)
    plot(time,POLY{day},time,POLY2{day});
    ylim([0 80]);
    pause(0.01);
end









% for i = 1:364
%     plot(1:24,Deriv1(i,:),1:24,Deriv2(i,:));
%     ylim([-4 4]);
%     pause(0.01);
% end
        

load Weather;

hour = 1:1:length(Wind_Chill_Mean_C);
   

% figure;
% plot(hour,Sea_Level_Pressure_Mean_C,hour,Sea_Level_Pressure_Mean_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Sea Level Pressure Mean');
% 
% figure;
% plot(hour,Clouds_Broken_Percentage_C,hour,Clouds_Broken_Percentage_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Clouds Broken Percentage');
% 
% figure;
% plot(hour,Dew_Point_90th_Percentile_C,hour,Dew_Point_90th_Percentile_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Dew Point 90th Percentile');
% 
% figure;
% plot(hour,Secondary_Wind_Direction_C,hour,Secondary_Wind_Direction_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Secondary Wind Direction');
% 
% figure;
% plot(hour,Prevailing_Wind_Percentage_C,hour,Prevailing_Wind_Percentage_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Prevailing Wind Percentage');
% 
% figure;
% plot(hour,Dew_Point_Mean_C,hour,Dew_Point_Mean_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Dew Point Mean');
% 
% figure;
% plot(hour,Cooling_Degree_Hours_C,hour,Cooling_Degree_Hours_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Cooling Degree Hours');
% 
% figure;
% plot(hour,Sea_Level_Pressure_10th_Percentile_C,hour,Sea_Level_Pressure_10th_Percentile_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Sea Level Pressure 10th Percentile');
% 
% figure;
% plot(hour,Mean_Wind_Vector_Magnitude_C,hour,Mean_Wind_Vector_Magnitude_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Mean Wind Vector Magnitude');
% 
% figure;
% plot(hour,Prevailing_Wind_Direction_C,hour,Prevailing_Wind_Direction_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Prevailing Wind Direction');
% 
% figure;
% plot(hour,Temperature_90th_Percentile_C,hour,Temperature_90th_Percentile_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Temperature 90th Percentile');
% 
% figure;
% plot(hour,Heating_Degree_Hours_C,hour,Heating_Degree_Hours_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Heating Degree Hours');
% 
% figure;
% plot(hour,Average_Wind_Speed_C,hour,Average_Wind_Speed_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Average Wind Speed');
% 
% figure;
% plot(hour,Mean_Wind_Vector_Direction_C,hour,Mean_Wind_Vector_Direction_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Mean Wind Vector Direction');
% 
% figure;
% plot(hour,Temperature_10th_Percentile_C,hour,Temperature_10th_Percentile_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Temperature 10th Percentile');
% 
% figure;
% plot(hour,Heat_Index_Mean_C,hour,Heat_Index_Mean_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Heat Index Mean');
% 
% figure;
% plot(hour,Secondary_Wind_Percentage_C,hour,Secondary_Wind_Percentage_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Secondary Wind Percentage');
% 
% figure;
% plot(hour,Clouds_Scattered_Percentage_C,hour,Clouds_Scattered_Percentage_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Clouds Scattered Percentage');
% 
% figure;
% plot(hour,Percentage_Calm_C,hour,Percentage_Calm_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Percentage Calm');
% 
% figure;
% plot(hour,Temperature_Mean_C,hour,Temperature_Mean_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Temperature Mean');
% 
% figure;
% plot(hour,Wind_Chill_Mean_C,hour,Wind_Chill_Mean_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Wind Chill Mean');
% 
% figure;
% plot(hour,Sea_Level_Pressure_90th_Percentile_C,hour,Sea_Level_Pressure_90th_Percentile_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Sea Level Pressure 90th Percentile');
% 
% figure;
% plot(hour,Clouds_Few_Percentage_C,hour,Clouds_Few_Percentage_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Clouds Few Percentage');
% 
% figure;
% plot(hour,Dew_Point_10th_Percentile_C,hour,Dew_Point_10th_Percentile_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Dew Point 10th Percentile');
% 
% figure;
% plot(hour,Clouds_Overcast_Percentage_C,hour,Clouds_Overcast_Percentage_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Clouds Overcast Percentage');
% 
% figure;
% plot(hour,Clouds_Clear_Percentage_C,hour,Clouds_Clear_Percentage_L);
% xlabel('Hour');
% legend('Cincinnati','Louisville');
% title('Clouds Clear Percentage');

PolyCounter = 1;
for d = 1:length(JanuaryC)
    PolyMonthMax(1,d) = {POLY{PolyCounter}};
    PolyMonthMin(1,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(FebruaryC)
    PolyMonthMax(2,d) = {POLY{PolyCounter}};
    PolyMonthMin(2,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(MarchC)
    PolyMonthMax(3,d) = {POLY{PolyCounter}};
    PolyMonthMin(3,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(AprilC)
    PolyMonthMax(4,d) = {POLY{PolyCounter}};
    PolyMonthMin(4,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(MayC)
    PolyMonthMax(5,d) = {POLY{PolyCounter}};
    PolyMonthMin(5,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(JuneC)
    PolyMonthMax(6,d) = {POLY{PolyCounter}};
    PolyMonthMin(6,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(JulyC)
    PolyMonthMax(7,d) = {POLY{PolyCounter}};
    PolyMonthMin(7,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(AugustC)
    PolyMonthMax(8,d) = {POLY{PolyCounter}};
    PolyMonthMin(8,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(SeptemberC)
    PolyMonthMax(9,d) = {POLY{PolyCounter}};
    PolyMonthMin(9,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(OctoberC)
    PolyMonthMax(10,d) = {POLY{PolyCounter}};
    PolyMonthMin(10,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(NovemberC)
    PolyMonthMax(11,d) = {POLY{PolyCounter}};
    PolyMonthMin(11,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
end

for d = 1:length(DecemberC)
    PolyMonthMax(12,d) = {POLY{PolyCounter}};
    PolyMonthMin(12,d) = {POLY2{PolyCounter}};
    PolyCounter = PolyCounter + 1;
    if PolyCounter == 365
        break;
    end
end

