% define datasets of experiment
myDatasets = {
    'cocomo81o','cocomo81s','cocomo81','cocomo81e',...
    'desharnaisL1','desharnais','desharnaisL2',...
    'desharnaisL3',...
    'nasa93','nasa93_center_1','nasa93_center_2','nasa93_center_5',...
    'sdr'...
    'albrecht',...
    'finnish','kemerer','maxwell','miyazaki94','telecom1',...
    %'china'
    };

% sum of win values for each error measure separately, over all datasets
allWinValues3Way = -1 * ones(7,90);
allLossValues3Way = -1 * ones(7,90);
allWinMinusLossValues3Way = -1 * ones(7,90);
allWinValuesLOO = -1 * ones(7,90);
allLossValuesLOO = -1 * ones(7,90);
allWinMinusLossValuesLOO = -1 * ones(7,90);
allWinValues10Way = -1 * ones(7,90);
allLossValues10Way = -1 * ones(7,90);
allWinMinusLossValues10Way = -1 * ones(7,90);

datasetSize = size(myDatasets,2);
for datasetCounter = 1:datasetSize
    
    % load win and loss values for 3 way
    clear winValues; clear lossValues;
    eval(['load(''workspaces\3Way\',char(myDatasets(datasetCounter)),'.mat'');']);
    winValues3Way = winValues';
    lossValues3Way = lossValues';
    winMinusLossValues3Way = (winValues-lossValues)';
    % then sum them up
    allWinValues3Way = allWinValues3Way + winValues3Way;
    allLossValues3Way = allLossValues3Way + lossValues3Way;
    allWinMinusLossValues3Way = allWinMinusLossValues3Way + winMinusLossValues3Way;
    
    % now do the same for LOO
    % load win and loss values
    clear winValues; clear lossValues;
    eval(['load(''workspaces\LOO\',char(myDatasets(datasetCounter)),'.mat'');']);
    winValuesLOO = winValues';
    lossValuesLOO = lossValues';
    winMinusLossValuesLOO = (winValues-lossValues)';
    % then sum them up
    allWinValuesLOO = allWinValuesLOO + winValuesLOO;
    allLossValuesLOO = allLossValuesLOO + lossValuesLOO;
    allWinMinusLossValuesLOO = allWinMinusLossValuesLOO + winMinusLossValuesLOO;
    
    % now do the same for 10Way
    % load win and loss values
    clear winValues; clear lossValues;
    eval(['load(''workspaces\10Way\',char(myDatasets(datasetCounter)),'.mat'');']);
    winValues10Way = winValues';
    lossValues10Way = lossValues';
    winMinusLossValues10Way = (winValues-lossValues)';
    % then sum them up
    allWinValues10Way = allWinValues10Way + winValues10Way;
    allLossValues10Way = allLossValues10Way + lossValues10Way;
    allWinMinusLossValues10Way = allWinMinusLossValues10Way + winMinusLossValues10Way;
end

% now start calcuating the absolute rank difference w.r.t icse paper
orderInIcse = [57	58	3	4	12	13	66	67	84	85	70	16	71	89	77	69	5	88	78	6	75	76	35	68	83	61	7	87	86	30	31	48	49	62	73	8	64	82	17	55	1	26	80	39	40	81	44	9	46	52	2	53	90	59	34	72	65	56	25	21	22	79	37	50	10	15	14	41	43	51	60	42	33	28	38	24	47	23	32	11	19	29	54	63	45	18 27 36 20 74];
myOrigin = [1:90];
allWinValues3Way = allWinValues3Way(:,orderInIcse);
allLossValues3Way = allLossValues3Way(:,orderInIcse);
allWinMinusLossValues3Way = allWinMinusLossValues3Way(:,orderInIcse);
allWinValuesLOO = allWinValuesLOO(:,orderInIcse);
allLossValuesLOO = allLossValuesLOO(:,orderInIcse);
allWinMinusLossValuesLOO = allWinMinusLossValuesLOO(:,orderInIcse);
allWinValues10Way = allWinValues10Way(:,orderInIcse);
allLossValues10Way = allLossValues10Way(:,orderInIcse);
allWinMinusLossValues10Way = allWinMinusLossValues10Way(:,orderInIcse);

% below variables will keep the abs-rank change for different error
% measures w.r.t. win, loss and (win-loss)
stabilityMAR3Way = zeros(90,3);
stabilityMMRE3Way = zeros(90,3);
stabilityMMER3Way = zeros(90,3);
stabilityMBRE3Way = zeros(90,3);
stabilityMIBRE3Way = zeros(90,3);
stabilityMDMRE3Way = zeros(90,3);
stabilityPRED3Way = zeros(90,3);

stabilityMARLOO = zeros(90,3);
stabilityMMRELOO = zeros(90,3);
stabilityMMERLOO = zeros(90,3);
stabilityMBRELOO = zeros(90,3);
stabilityMIBRELOO = zeros(90,3);
stabilityMDMRELOO = zeros(90,3);
stabilityPREDLOO = zeros(90,3);

stabilityMAR10Way = zeros(90,3);
stabilityMMRE10Way = zeros(90,3);
stabilityMMER10Way = zeros(90,3);
stabilityMBRE10Way = zeros(90,3);
stabilityMIBRE10Way = zeros(90,3);
stabilityMDMRE10Way = zeros(90,3);
stabilityPRED10Way = zeros(90,3);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% now get sorted indices for win, loss and (win-loss)
%%%% MAR 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues3Way(1,:), 'descend');
stabilityMAR3Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues3Way(1,:), 'ascend');
stabilityMAR3Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues3Way(1,:), 'descend');
stabilityMAR3Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MMRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues3Way(2,:), 'descend');
stabilityMMRE3Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues3Way(2,:), 'ascend');
stabilityMMRE3Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues3Way(2,:), 'descend');
stabilityMMRE3Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MMER 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues3Way(3,:), 'descend');
stabilityMMER3Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues3Way(3,:), 'ascend');
stabilityMMER3Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues3Way(3,:), 'descend');
stabilityMMER3Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MBRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues3Way(4,:), 'descend');
stabilityMBRE3Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues3Way(4,:), 'ascend');
stabilityMBRE3Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues3Way(4,:), 'descend');
stabilityMBRE3Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MIBRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues3Way(5,:), 'descend');
stabilityMIBRE3Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues3Way(5,:), 'ascend');
stabilityMIBRE3Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues3Way(5,:), 'descend');
stabilityMIBRE3Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MDMRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues3Way(6,:), 'descend');
stabilityMDMRE3Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues3Way(6,:), 'ascend');
stabilityMDMRE3Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues3Way(6,:), 'descend');
stabilityMDMRE3Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% PRED 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues3Way(7,:), 'descend');
stabilityPRED3Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues3Way(7,:), 'ascend');
stabilityPRED3Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues3Way(7,:), 'descend');
stabilityPRED3Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% NOW START DOING THE STABILITY CALCULATIONS %%%%%%
%%%%%% FOR LOO BELOW BASICALLY DO THE SAME STUFF AGAIN %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MAR 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValuesLOO(1,:), 'descend');
stabilityMARLOO(:,1) = winIndices';
[C lossIndices] = sort(allLossValuesLOO(1,:), 'ascend');
stabilityMARLOO(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValuesLOO(1,:), 'descend');
stabilityMARLOO(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MMRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValuesLOO(2,:), 'descend');
stabilityMMRELOO(:,1) = winIndices';
[C lossIndices] = sort(allLossValuesLOO(2,:), 'ascend');
stabilityMMRELOO(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValuesLOO(2,:), 'descend');
stabilityMMRELOO(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MMER 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValuesLOO(3,:), 'descend');
stabilityMMERLOO(:,1) = winIndices';
[C lossIndices] = sort(allLossValuesLOO(3,:), 'ascend');
stabilityMMERLOO(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValuesLOO(3,:), 'descend');
stabilityMMERLOO(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MBRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValuesLOO(4,:), 'descend');
stabilityMBRELOO(:,1) = winIndices';
[C lossIndices] = sort(allLossValuesLOO(4,:), 'ascend');
stabilityMBRELOO(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValuesLOO(4,:), 'descend');
stabilityMBRELOO(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MIBRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValuesLOO(5,:), 'descend');
stabilityMIBRELOO(:,1) = winIndices';
[C lossIndices] = sort(allLossValuesLOO(5,:), 'ascend');
stabilityMIBRELOO(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValuesLOO(5,:), 'descend');
stabilityMIBRELOO(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MDMRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValuesLOO(6,:), 'descend');
stabilityMDMRELOO(:,1) = winIndices';
[C lossIndices] = sort(allLossValuesLOO(6,:), 'ascend');
stabilityMDMRELOO(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValuesLOO(6,:), 'descend');
stabilityMDMRELOO(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% PRED 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValuesLOO(7,:), 'descend');
stabilityPREDLOO(:,1) = winIndices';
[C lossIndices] = sort(allLossValuesLOO(7,:), 'ascend');
stabilityPREDLOO(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValuesLOO(7,:), 'descend');
stabilityPREDLOO(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% NOW START DOING THE STABILITY CALCULATIONS %%%%%%
%%%%%% FOR 10Way BELOW BASICALLY DO THE SAME STUFF ONCE MORE AGAIN %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MAR 10-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues10Way(1,:), 'descend');
stabilityMAR10Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues10Way(1,:), 'ascend');
stabilityMAR10Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues10Way(1,:), 'descend');
stabilityMAR10Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MMRE 10Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues10Way(2,:), 'descend');
stabilityMMRE10Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues10Way(2,:), 'ascend');
stabilityMMRE10Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues10Way(2,:), 'descend');
stabilityMMRE10Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MMER 10Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues10Way(3,:), 'descend');
stabilityMMER10Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues10Way(3,:), 'ascend');
stabilityMMER10Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues10Way(3,:), 'descend');
stabilityMMER10Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MBRE 10Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues10Way(4,:), 'descend');
stabilityMBRE10Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues10Way(4,:), 'ascend');
stabilityMBRE10Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues10Way(4,:), 'descend');
stabilityMBRE10Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MIBRE 10Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues10Way(5,:), 'descend');
stabilityMIBRE10Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues10Way(5,:), 'ascend');
stabilityMIBRE10Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues10Way(5,:), 'descend');
stabilityMIBRE10Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% MDMRE 10Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues10Way(6,:), 'descend');
stabilityMDMRE10Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues10Way(6,:), 'ascend');
stabilityMDMRE10Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues10Way(6,:), 'descend');
stabilityMDMRE10Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% PRED 10Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
winIndices = []; lossIndices = []; winMinusLossIndices = [];
[C winIndices] = sort(allWinValues10Way(7,:), 'descend');
stabilityPRED10Way(:,1) = winIndices';
[C lossIndices] = sort(allLossValues10Way(7,:), 'ascend');
stabilityPRED10Way(:,2) = lossIndices';
[C winMinusLossIndices] = sort(allWinMinusLossValues10Way(7,:), 'descend');
stabilityPRED10Way(:,3) = winMinusLossIndices';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% and now plot for each error measure
% how much the absolute rank difference is
% h=figure;
% subplot(3,1,1); hold on; plot(stabilityMAR3Way(:,1),'r');plot(stabilityMARLOO(:,1),'g'); hold off;
% title('Win');ylabel('MAR');legend('3Way','LOO');
% subplot(3,1,2); hold on; plot(stabilityMAR3Way(:,2),'r');plot(stabilityMARLOO(:,2),'g'); hold off;
% title('Loss');ylabel('MAR');legend('3Way','LOO');
% subplot(3,1,3); hold on; plot(stabilityMAR3Way(:,3),'r');plot(stabilityMARLOO(:,3),'g'); hold off;
% title('Win-Loss');ylabel('MAR');legend('3Way','LOO');
% eval(['print(h,''-dpng'', ''plots\orderedRanks\MAR-Order-Rank.png'');']);
% eval(['print(h,''-dpdf'', ''plots\orderedRanks\MAR-Order-Rank.pdf'');']);
% close all;
% 
% h=figure;
% subplot(3,1,1); hold on; plot(stabilityMMRE3Way(:,1),'r');plot(stabilityMMRELOO(:,1),'g'); hold off;
% title('Win');ylabel('MMRE');legend('3Way','LOO');
% subplot(3,1,2); hold on; plot(stabilityMMRE3Way(:,2),'r');plot(stabilityMMRELOO(:,2),'g'); hold off;
% title('Loss');ylabel('MMRE');legend('3Way','LOO');
% subplot(3,1,3); hold on; plot(stabilityMMRE3Way(:,3),'r');plot(stabilityMMRELOO(:,3),'g'); hold off;
% title('Win-Loss');ylabel('MMRE');legend('3Way','LOO');
% eval(['print(h,''-dpng'', ''plots\orderedRanks\MMRE-Order-Rank.png'');']);
% eval(['print(h,''-dpdf'', ''plots\orderedRanks\MMRE-Order-Rank.pdf'');']);
% close all;
% 
% h=figure;
% subplot(3,1,1); hold on; plot(stabilityMMER3Way(:,1),'r');plot(stabilityMMERLOO(:,1),'g'); hold off;
% title('Win');ylabel('MMER');legend('3Way','LOO');
% subplot(3,1,2); hold on; plot(stabilityMMER3Way(:,2),'r');plot(stabilityMMERLOO(:,2),'g'); hold off;
% title('Loss');ylabel('MMER');legend('3Way','LOO');
% subplot(3,1,3); hold on; plot(stabilityMMER3Way(:,3),'r');plot(stabilityMMERLOO(:,3),'g'); hold off;
% title('Win-Loss');ylabel('MMER');legend('3Way','LOO');
% eval(['print(h,''-dpng'', ''plots\orderedRanks\MMER-Order-Rank.png'');']);
% eval(['print(h,''-dpdf'', ''plots\orderedRanks\MMER-Order-Rank.pdf'');']);
% close all;
% 
% h=figure;
% subplot(3,1,1); hold on; plot(stabilityMBRE3Way(:,1),'r');plot(stabilityMBRELOO(:,1),'g'); hold off;
% title('Win');ylabel('MBRE');legend('3Way','LOO');
% subplot(3,1,2); hold on; plot(stabilityMBRE3Way(:,2),'r');plot(stabilityMBRELOO(:,2),'g'); hold off;
% title('Loss');ylabel('MBRE');legend('3Way','LOO');
% subplot(3,1,3); hold on; plot(stabilityMBRE3Way(:,3),'r');plot(stabilityMBRELOO(:,3),'g'); hold off;
% title('Win-Loss');ylabel('MBRE');legend('3Way','LOO');
% eval(['print(h,''-dpng'', ''plots\orderedRanks\MBRE-Order-Rank.png'');']);
% eval(['print(h,''-dpdf'', ''plots\orderedRanks\MBRE-Order-Rank.pdf'');']);
% close all;
% 
% h=figure;
% subplot(3,1,1); hold on; plot(stabilityMIBRE3Way(:,1),'r');plot(stabilityMIBRELOO(:,1),'g'); hold off;
% title('Win');ylabel('MIBRE');legend('3Way','LOO');
% subplot(3,1,2); hold on; plot(stabilityMIBRE3Way(:,2),'r');plot(stabilityMIBRELOO(:,2),'g'); hold off;
% title('Loss');ylabel('MIBRE');legend('3Way','LOO');
% subplot(3,1,3); hold on; plot(stabilityMIBRE3Way(:,3),'r');plot(stabilityMIBRELOO(:,3),'g'); hold off;
% title('Win-Loss');ylabel('MIBRE');legend('3Way','LOO');
% eval(['print(h,''-dpng'', ''plots\orderedRanks\MIBRE-Order-Rank.png'');']);
% eval(['print(h,''-dpdf'', ''plots\orderedRanks\MIBRE-Order-Rank.pdf'');']);
% close all;
% 
% h=figure;
% subplot(3,1,1); hold on; plot(stabilityMDMRE3Way(:,1),'r');plot(stabilityMDMRELOO(:,1),'g'); hold off;
% title('Win');ylabel('MDMRE');legend('3Way','LOO');
% subplot(3,1,2); hold on; plot(stabilityMDMRE3Way(:,2),'r');plot(stabilityMDMRELOO(:,2),'g'); hold off;
% title('Loss');ylabel('MDMRE');legend('3Way','LOO');
% subplot(3,1,3); hold on; plot(stabilityMDMRE3Way(:,3),'r');plot(stabilityMDMRELOO(:,3),'g'); hold off;
% title('Win-Loss');ylabel('MDMRE');legend('3Way','LOO');
% eval(['print(h,''-dpng'', ''plots\orderedRanks\MDMRE-Order-Rank.png'');']);
% eval(['print(h,''-dpdf'', ''plots\orderedRanks\MDMRE-Order-Rank.pdf'');']);
% close all;
% 
% h=figure;
% subplot(3,1,1); hold on; plot(stabilityPRED3Way(:,1),'r');plot(stabilityPREDLOO(:,1),'g'); hold off;
% title('Win');ylabel('PRED');legend('3Way','LOO');
% subplot(3,1,2); hold on; plot(stabilityPRED3Way(:,2),'r');plot(stabilityPREDLOO(:,2),'g'); hold off;
% title('Loss');ylabel('PRED');legend('3Way','LOO');
% subplot(3,1,3); hold on; plot(stabilityPRED3Way(:,3),'r');plot(stabilityPREDLOO(:,3),'g'); hold off;
% title('Win-Loss');ylabel('PRED');legend('3Way','LOO');
% eval(['print(h,''-dpng'', ''plots\orderedRanks\PRED-Order-Rank.png'');']);
% eval(['print(h,''-dpdf'', ''plots\orderedRanks\PRED-Order-Rank.pdf'');']);
% close all;

% write the distribution of ranks into an excel
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMAR3Way, 'MAR','B2:D91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMMRE3Way, 'MMRE','B2:D91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMMER3Way, 'MMER','B2:D91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMBRE3Way, 'MBRE','B2:D91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMIBRE3Way, 'MIBRE','B2:D91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMDMRE3Way, 'MDMRE','B2:D91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityPRED3Way, 'PRED','B2:D91');

xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMARLOO, 'MAR','F2:H91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMMRELOO, 'MMRE','F2:H91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMMERLOO, 'MMER','F2:H91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMBRELOO, 'MBRE','F2:H91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMIBRELOO, 'MIBRE','F2:H91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMDMRELOO, 'MDMRE','F2:H91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityPREDLOO, 'PRED','F2:H91');

xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMARLOO, 'MAR','J2:L91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMMRELOO, 'MMRE','J2:L91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMMERLOO, 'MMER','J2:L91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMBRELOO, 'MBRE','J2:L91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMIBRELOO, 'MIBRE','J2:L91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityMDMRELOO, 'MDMRE','J2:L91');
xlswrite('plots\orderedRanks\rankDistribution.xls',stabilityPREDLOO, 'PRED','J2:L91');
