% 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'
    };

% for 3Way and LOO, define 90 by 3 matrices for each error measure
% 90 by 3 matrices will keep the appearance of methods on top 16
% first column is appearance w.r.t. win values, second is w.r.t loss
% and the third one is w.r.t. (win-loss)
% below is for top 16
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);
% and below is for bottom 16
stabilityMAR3WayBottom = zeros(90,3);
stabilityMMRE3WayBottom = zeros(90,3);
stabilityMMER3WayBottom = zeros(90,3);
stabilityMBRE3WayBottom = zeros(90,3);
stabilityMIBRE3WayBottom = zeros(90,3);
stabilityMDMRE3WayBottom = zeros(90,3);
stabilityPRED3WayBottom = zeros(90,3);


% below is for top 16
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);
% below is for bottom 16
stabilityMARLOOBottom = zeros(90,3);
stabilityMMRELOOBottom = zeros(90,3);
stabilityMMERLOOBottom = zeros(90,3);
stabilityMBRELOOBottom = zeros(90,3);
stabilityMIBRELOOBottom = zeros(90,3);
stabilityMDMRELOOBottom = zeros(90,3);
stabilityPREDLOOBottom = zeros(90,3);

datasetSize = size(myDatasets,2);
for datasetCounter = 1:datasetSize
    
    % load win and loss values
    eval(['load(''workspaces\3Way\',char(myDatasets(datasetCounter)),'.mat'');']);
    winValues3Way = winValues';
    lossValues3Way = lossValues';
    winMinusLossValues3Way = (winValues-lossValues)';
    
    % convert the order to icse 
    % orderInIcse = [41	51	3	4	17	20	27	36	48	65	80	5	6	67	66	12	39	86	81	89	60	61	78	76	59	42	87	74	82	30	31	79	73	55	23	88	63	75	44	45	68	72	69	47	85	49	77	32	33	64	70	50	52	83	40	58	1	2	54	71	26	34	84	37	57	7	8	24	16	11	13	56	35	90	21	22	15	19	62	43	46	38	25	9	10	29	28 18 14 53];
    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];
    winValues3Way = winValues3Way(:,orderInIcse);
    lossValues3Way = lossValues3Way(:,orderInIcse);
    winMinusLossValues3Way = winMinusLossValues3Way(:,orderInIcse);
    
    % now get sorted indices for win, loss and (win-loss)  
    %%%% MAR 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValues3Way(1,:), 'descend');
    stabilityMAR3Way(winIndices(1:16),1) = stabilityMAR3Way(winIndices(1:16),1) + 1; 
    stabilityMAR3WayBottom(winIndices(75:90),1) = stabilityMAR3WayBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValues3Way(1,:), 'ascend');
    stabilityMAR3Way(lossIndices(1:16),2) = stabilityMAR3Way(lossIndices(1:16),2) + 1; 
    stabilityMAR3WayBottom(lossIndices(75:90),2) = stabilityMAR3WayBottom(lossIndices(75:90),2) + 1; 
    [C winMinusLossIndices] = sort(winMinusLossValues3Way(1,:), 'descend');
    stabilityMAR3Way(winMinusLossIndices(1:16),3) = stabilityMAR3Way(winMinusLossIndices(1:16),3) + 1; 
    stabilityMAR3WayBottom(winMinusLossIndices(75:90),3) = stabilityMAR3WayBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MMRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValues3Way(2,:), 'descend');
    stabilityMMRE3Way(winIndices(1:16),1) = stabilityMMRE3Way(winIndices(1:16),1) + 1; 
    stabilityMMRE3WayBottom(winIndices(75:90),1) = stabilityMMRE3WayBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValues3Way(2,:), 'ascend');
    stabilityMMRE3Way(lossIndices(1:16),2) = stabilityMMRE3Way(lossIndices(1:16),2) + 1;
    stabilityMMRE3WayBottom(lossIndices(75:90),2) = stabilityMMRE3WayBottom(lossIndices(75:90),2) + 1;
    [C winMinusLossIndices] = sort(winMinusLossValues3Way(2,:), 'descend');
    stabilityMMRE3Way(winMinusLossIndices(1:16),3) = stabilityMMRE3Way(winMinusLossIndices(1:16),3) + 1; 
    stabilityMMRE3WayBottom(winMinusLossIndices(75:90),3) = stabilityMMRE3WayBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MMER 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValues3Way(3,:), 'descend');
    stabilityMMER3Way(winIndices(1:16),1) = stabilityMMER3Way(winIndices(1:16),1) + 1; 
    stabilityMMER3WayBottom(winIndices(75:90),1) = stabilityMMER3WayBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValues3Way(3,:), 'ascend');
    stabilityMMER3Way(lossIndices(1:16),2) = stabilityMMER3Way(lossIndices(1:16),2) + 1; 
    stabilityMMER3WayBottom(lossIndices(75:90),2) = stabilityMMER3WayBottom(lossIndices(75:90),2) + 1; 
    [C winMinusLossIndices] = sort(winMinusLossValues3Way(3,:), 'descend');
    stabilityMMER3Way(winMinusLossIndices(1:16),3) = stabilityMMER3Way(winMinusLossIndices(1:16),3) + 1; 
    stabilityMMER3WayBottom(winMinusLossIndices(75:90),3) = stabilityMMER3WayBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MBRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValues3Way(4,:), 'descend');
    stabilityMBRE3Way(winIndices(1:16),1) = stabilityMBRE3Way(winIndices(1:16),1) + 1; 
    stabilityMBRE3WayBottom(winIndices(75:90),1) = stabilityMBRE3WayBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValues3Way(4,:), 'ascend');
    stabilityMBRE3Way(lossIndices(1:16),2) = stabilityMBRE3Way(lossIndices(1:16),2) + 1; 
    stabilityMBRE3WayBottom(lossIndices(75:90),2) = stabilityMBRE3WayBottom(lossIndices(75:90),2) + 1; 
    [C winMinusLossIndices] = sort(winMinusLossValues3Way(4,:), 'descend');
    stabilityMBRE3Way(winMinusLossIndices(1:16),3) = stabilityMBRE3Way(winMinusLossIndices(1:16),3) + 1; 
    stabilityMBRE3WayBottom(winMinusLossIndices(75:90),3) = stabilityMBRE3WayBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MIBRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValues3Way(5,:), 'descend');
    stabilityMIBRE3Way(winIndices(1:16),1) = stabilityMIBRE3Way(winIndices(1:16),1) + 1; 
    stabilityMIBRE3WayBottom(winIndices(75:90),1) = stabilityMIBRE3WayBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValues3Way(5,:), 'ascend');
    stabilityMIBRE3Way(lossIndices(1:16),2) = stabilityMIBRE3Way(lossIndices(1:16),2) + 1;
    stabilityMIBRE3WayBottom(lossIndices(75:90),2) = stabilityMIBRE3WayBottom(lossIndices(75:90),2) + 1;
    [C winMinusLossIndices] = sort(winMinusLossValues3Way(5,:), 'descend');
    stabilityMIBRE3Way(winMinusLossIndices(1:16),3) = stabilityMIBRE3Way(winMinusLossIndices(1:16),3) + 1; 
    stabilityMIBRE3WayBottom(winMinusLossIndices(75:90),3) = stabilityMIBRE3WayBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MDMRE 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValues3Way(6,:), 'descend');
    stabilityMDMRE3Way(winIndices(1:16),1) = stabilityMDMRE3Way(winIndices(1:16),1) + 1; 
    stabilityMDMRE3WayBottom(winIndices(75:90),1) = stabilityMDMRE3WayBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValues3Way(6,:), 'ascend');
    stabilityMDMRE3Way(lossIndices(1:16),2) = stabilityMDMRE3Way(lossIndices(1:16),2) + 1;
    stabilityMDMRE3WayBottom(lossIndices(75:90),2) = stabilityMDMRE3WayBottom(lossIndices(75:90),2) + 1;
    [C winMinusLossIndices] = sort(winMinusLossValues3Way(6,:), 'descend');
    stabilityMDMRE3Way(winMinusLossIndices(1:16),3) = stabilityMDMRE3Way(winMinusLossIndices(1:16),3) + 1; 
    stabilityMDMRE3WayBottom(winMinusLossIndices(75:90),3) = stabilityMDMRE3WayBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% PRED 3-Way %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValues3Way(7,:), 'descend');
    stabilityPRED3Way(winIndices(1:16),1) = stabilityPRED3Way(winIndices(1:16),1) + 1; 
    stabilityPRED3WayBottom(winIndices(75:90),1) = stabilityPRED3WayBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValues3Way(7,:), 'ascend');
    stabilityPRED3Way(lossIndices(1:16),2) = stabilityPRED3Way(lossIndices(1:16),2) + 1;
    stabilityPRED3WayBottom(lossIndices(75:90),2) = stabilityPRED3WayBottom(lossIndices(75:90),2) + 1;
    [C winMinusLossIndices] = sort(winMinusLossValues3Way(7,:), 'descend');
    stabilityPRED3Way(winMinusLossIndices(1:16),3) = stabilityPRED3Way(winMinusLossIndices(1:16),3) + 1; 
    stabilityPRED3WayBottom(winMinusLossIndices(75:90),3) = stabilityPRED3WayBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%% NOW START DOING THE STABILITY CALCULATIONS %%%%%%
    %%%%%% FOR LOO BELOW BASICALL DO THE SAME STUFF AGAIN %%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    % load win and loss values
    eval(['load(''workspaces\LOO\',char(myDatasets(datasetCounter)),'.mat'');']);
    winValuesLOO = winValues';
    lossValuesLOO = lossValues';
    winMinusLossValuesLOO = (winValues-lossValues)';
    % now get sorted indices for win, loss and (win-loss)
    
    % convert the order to icse 
    orderInIcse = [41	51	3	4	17	20	27	36	48	65	80	5	6	67	66	12	39	86	81	89	60	61	78	76	59	42	87	74	82	30	31	79	73	55	23	88	63	75	44	45	68	72	69	47	85	49	77	32	33	64	70	50	52	83	40	58	1	2	54	71	26	34	84	37	57	7	8	24	16	11	13	56	35	90	21	22	15	19	62	43	46	38	25	9	10	29	28 18 14 53];
    winValuesLOO = winValuesLOO(:,orderInIcse);
    lossValuesLOO = lossValuesLOO(:,orderInIcse);
    winMinusLossValuesLOO = winMinusLossValuesLOO(:,orderInIcse);
        
    %%%% MAR LOO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValuesLOO(1,:), 'descend');
    stabilityMARLOO(winIndices(1:16),1) = stabilityMARLOO(winIndices(1:16),1) + 1; 
    stabilityMARLOOBottom(winIndices(75:90),1) = stabilityMARLOOBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValuesLOO(1,:), 'ascend');
    stabilityMARLOO(lossIndices(1:16),2) = stabilityMARLOO(lossIndices(1:16),2) + 1; 
    stabilityMARLOOBottom(lossIndices(75:90),2) = stabilityMARLOOBottom(lossIndices(75:90),2) + 1; 
    [C winMinusLossIndices] = sort(winMinusLossValuesLOO(1,:), 'descend');
    stabilityMARLOO(winMinusLossIndices(1:16),3) = stabilityMARLOO(winMinusLossIndices(1:16),3) + 1; 
    stabilityMARLOOBottom(winMinusLossIndices(75:90),3) = stabilityMARLOOBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MMRE LOO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValuesLOO(2,:), 'descend');
    stabilityMMRELOO(winIndices(1:16),1) = stabilityMMRELOO(winIndices(1:16),1) + 1; 
    stabilityMMRELOOBottom(winIndices(75:90),1) = stabilityMMRELOOBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValuesLOO(2,:), 'ascend');
    stabilityMMRELOO(lossIndices(1:16),2) = stabilityMMRELOO(lossIndices(1:16),2) + 1;
    stabilityMMRELOOBottom(lossIndices(75:90),2) = stabilityMMRELOOBottom(lossIndices(75:90),2) + 1;
    [C winMinusLossIndices] = sort(winMinusLossValuesLOO(2,:), 'descend');
    stabilityMMRELOO(winMinusLossIndices(1:16),3) = stabilityMMRELOO(winMinusLossIndices(1:16),3) + 1; 
    stabilityMMRELOOBottom(winMinusLossIndices(75:90),3) = stabilityMMRELOOBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MMER LOO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValuesLOO(3,:), 'descend');
    stabilityMMERLOO(winIndices(1:16),1) = stabilityMMERLOO(winIndices(1:16),1) + 1; 
    stabilityMMERLOOBottom(winIndices(75:90),1) = stabilityMMERLOOBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValuesLOO(3,:), 'ascend');
    stabilityMMERLOO(lossIndices(1:16),2) = stabilityMMERLOO(lossIndices(1:16),2) + 1; 
    stabilityMMERLOOBottom(lossIndices(75:90),2) = stabilityMMERLOOBottom(lossIndices(75:90),2) + 1; 
    [C winMinusLossIndices] = sort(winMinusLossValuesLOO(3,:), 'descend');
    stabilityMMERLOO(winMinusLossIndices(1:16),3) = stabilityMMERLOO(winMinusLossIndices(1:16),3) + 1; 
    stabilityMMERLOOBottom(winMinusLossIndices(75:90),3) = stabilityMMERLOOBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MBRE LOO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValuesLOO(4,:), 'descend');
    stabilityMBRELOO(winIndices(1:16),1) = stabilityMBRELOO(winIndices(1:16),1) + 1; 
    stabilityMBRELOOBottom(winIndices(75:90),1) = stabilityMBRELOOBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValuesLOO(4,:), 'ascend');
    stabilityMBRELOO(lossIndices(1:16),2) = stabilityMBRELOO(lossIndices(1:16),2) + 1; 
    stabilityMBRELOOBottom(lossIndices(75:90),2) = stabilityMBRELOOBottom(lossIndices(75:90),2) + 1; 
    [C winMinusLossIndices] = sort(winMinusLossValuesLOO(4,:), 'descend');
    stabilityMBRELOO(winMinusLossIndices(1:16),3) = stabilityMBRELOO(winMinusLossIndices(1:16),3) + 1; 
    stabilityMBRELOOBottom(winMinusLossIndices(75:90),3) = stabilityMBRELOOBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MIBRE LOO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValuesLOO(5,:), 'descend');
    stabilityMIBRELOO(winIndices(1:16),1) = stabilityMIBRELOO(winIndices(1:16),1) + 1; 
    stabilityMIBRELOOBottom(winIndices(75:90),1) = stabilityMIBRELOOBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValuesLOO(5,:), 'ascend');
    stabilityMIBRELOO(lossIndices(1:16),2) = stabilityMIBRELOO(lossIndices(1:16),2) + 1;
    stabilityMIBRELOOBottom(lossIndices(75:90),2) = stabilityMIBRELOOBottom(lossIndices(75:90),2) + 1;
    [C winMinusLossIndices] = sort(winMinusLossValuesLOO(5,:), 'descend');
    stabilityMIBRELOO(winMinusLossIndices(1:16),3) = stabilityMIBRELOO(winMinusLossIndices(1:16),3) + 1; 
    stabilityMIBRELOOBottom(winMinusLossIndices(75:90),3) = stabilityMIBRELOOBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% MDMRE LOO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValuesLOO(6,:), 'descend');
    stabilityMDMRELOO(winIndices(1:16),1) = stabilityMDMRELOO(winIndices(1:16),1) + 1; 
    stabilityMDMRELOOBottom(winIndices(75:90),1) = stabilityMDMRELOOBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValuesLOO(6,:), 'ascend');
    stabilityMDMRELOO(lossIndices(1:16),2) = stabilityMDMRELOO(lossIndices(1:16),2) + 1;
    stabilityMDMRELOOBottom(lossIndices(75:90),2) = stabilityMDMRELOOBottom(lossIndices(75:90),2) + 1;
    [C winMinusLossIndices] = sort(winMinusLossValuesLOO(6,:), 'descend');
    stabilityMDMRELOO(winMinusLossIndices(1:16),3) = stabilityMDMRELOO(winMinusLossIndices(1:16),3) + 1; 
    stabilityMDMRELOOBottom(winMinusLossIndices(75:90),3) = stabilityMDMRELOOBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%% PRED LOO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    [C winIndices] = sort(winValuesLOO(7,:), 'descend');
    stabilityPREDLOO(winIndices(1:16),1) = stabilityPREDLOO(winIndices(1:16),1) + 1; 
    stabilityPREDLOOBottom(winIndices(75:90),1) = stabilityPREDLOOBottom(winIndices(75:90),1) + 1; 
    [C lossIndices] = sort(lossValuesLOO(7,:), 'ascend');
    stabilityPREDLOO(lossIndices(1:16),2) = stabilityPREDLOO(lossIndices(1:16),2) + 1;
    stabilityPREDLOOBottom(lossIndices(75:90),2) = stabilityPREDLOOBottom(lossIndices(75:90),2) + 1;
    [C winMinusLossIndices] = sort(winMinusLossValuesLOO(7,:), 'descend');
    stabilityPREDLOO(winMinusLossIndices(1:16),3) = stabilityPREDLOO(winMinusLossIndices(1:16),3) + 1; 
    stabilityPREDLOOBottom(winMinusLossIndices(75:90),3) = stabilityPREDLOOBottom(winMinusLossIndices(75:90),3) + 1; 
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

% write the results into excel, where
% each sheet corresponds to an error measure

% first write occurrence of top 16
xlswrite('plots/stability.xls',stabilityMAR3Way, 'MAR-Top16');
xlswrite('plots/stability.xls',stabilityMMRE3Way, 'MMRE-Top16');
xlswrite('plots/stability.xls',stabilityMMER3Way, 'MMER-Top16');
xlswrite('plots/stability.xls',stabilityMBRE3Way, 'MBRE-Top16');
xlswrite('plots/stability.xls',stabilityMIBRE3Way, 'MIBRE-Top16');
xlswrite('plots/stability.xls',stabilityMDMRE3Way, 'MDMRE-Top16');
xlswrite('plots/stability.xls',stabilityPRED3Way, 'PRED25-Top16');
% then write occurrence of bottom 16
xlswrite('plots/stability.xls',stabilityMAR3WayBottom, 'MAR-Bottom16');
xlswrite('plots/stability.xls',stabilityMMRE3WayBottom, 'MMRE-Bottom16');
xlswrite('plots/stability.xls',stabilityMMER3WayBottom, 'MMER-Bottom16');
xlswrite('plots/stability.xls',stabilityMBRE3WayBottom, 'MBRE-Bottom16');
xlswrite('plots/stability.xls',stabilityMIBRE3WayBottom, 'MIBRE-Bottom16');
xlswrite('plots/stability.xls',stabilityMDMRE3WayBottom, 'MDMRE-Bottom16');
xlswrite('plots/stability.xls',stabilityPRED3WayBottom, 'PRED25-Bottom16');
% this time, top 16 for LOO
xlswrite('plots/stability.xls',stabilityMARLOO, 'MAR-Top16','E1:G90');
xlswrite('plots/stability.xls',stabilityMMRELOO, 'MMRE-Top16','E1:G90');
xlswrite('plots/stability.xls',stabilityMMERLOO, 'MMER-Top16','E1:G90');
xlswrite('plots/stability.xls',stabilityMBRELOO, 'MBRE-Top16','E1:G90');
xlswrite('plots/stability.xls',stabilityMIBRELOO, 'MIBRE-Top16','E1:G90');
xlswrite('plots/stability.xls',stabilityMDMRELOO, 'MDMRE-Top16','E1:G90');
xlswrite('plots/stability.xls',stabilityPREDLOO, 'PRED25-Top16','E1:G90');
% then for the bottom 16
xlswrite('plots/stability.xls',stabilityMARLOOBottom, 'MAR-Bottom16','E1:G90');
xlswrite('plots/stability.xls',stabilityMMRELOOBottom, 'MMRE-Bottom16','E1:G90');
xlswrite('plots/stability.xls',stabilityMMERLOOBottom, 'MMER-Bottom16','E1:G90');
xlswrite('plots/stability.xls',stabilityMBRELOOBottom, 'MBRE-Bottom16','E1:G90');
xlswrite('plots/stability.xls',stabilityMIBRELOOBottom, 'MIBRE-Bottom16','E1:G90');
xlswrite('plots/stability.xls',stabilityMDMRELOOBottom, 'MDMRE-Bottom16','E1:G90');
xlswrite('plots/stability.xls',stabilityPREDLOOBottom, 'PRED25-Bottom16','E1:G90');


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




