Improve the following sections of MATLAB code, make sure the code is a lot shorter and more efficient.
%% Plot results Score confidence interval & computation time MM-CPD
if is_nonzero
if ~merge_F1_plot
for i_ST_type = 1:n_ST_type
figure()
% line plot of maximum F1 score for each number of windows with confidence intervals
        errorbar(N_list, F1_score_max(:, :, i_ST_type), F1_score_CI_neg_max(:, :, i_ST_type), F1_score_CI_pos_max(:, :, i_ST_type))
        % set y-axis label
        ylabel('F1 score')
        title(strcat("Type ", num2str(i_ST_type)))
    end
else
    % line plot of maximum F1 score for each number of windows with confidence intervals
    errorbar(N_list, F1_score_max, F1_score_CI_neg_max, F1_score_CI_pos_max)
    % set y-axis label
    ylabel('F1 score')
end
else
figure()
% line plot of maximum specificity for each number of windows with confidence intervals
errorbar(N_list, specificity_max, specificity_CI_neg_max, specificity_CI_pos_max)
% set y-axis label
ylabel('Specificity')
end
% format axes
xlabel('N')
xticks(N_list)
set(gca, 'Fontsize', 19)
set(gca, 'LineWidth', 1.2)
set(gca, 'Position', [.2 .2 0.7 .7])
set(gca, 'TickLength', [0.02 0.035])
figure()
% scatterplot of MM-CPD time of computation for each number of windows
scatter(N_list, t_analysis)
hold on
box on
% format axes
xlabel('N')
ylabel('CPU time (s)')
xticks(N_list)
set(gca,'Position',[.2 .2 0.7 .7])
set(gca,'Fontsize',19)
set(gca,'TickLength',[0.02 0.035])
set(gca,'LineWidth',1.2)
%% Plot results F1 Score or Specificity
if is_nonzero
if ~merge_F1_plot
for i_ST_type = 1:n_ST_type
for i_N = 1:n_N

N = N_list(i_N);
% create meshgrid
            [x_grid, y_grid] = meshgrid(threshold_list, min_window_list);
            figure()
            % retreive F1 score matrix of given i_N
            F1_score_plot = F1_score(:, :, i_N, i_ST_type);
            % create contourplot with stepsize 0.005
            contourf(x_grid, y_grid, F1_score_plot, 0:0.05:1);
            % apply colormap
            colormap(flipud(jet))
            % create colorbar
            h = colorbar();
            % set title string depending given i_N
            if i_N == 1
                titlestr = strcat("Type ", num2str(i_ST_type), " Single window (N = 1)");   
            else
                titlestr = strcat("Type ", num2str(i_ST_type), " Multiple windows (N = ", num2str(N), ")");   
            end
            % set colorbar title
            hl = title(h, 'F1 score', 'FontSize', 13);
            % format plot title and axes
            title_handle = title(titlestr);
            xlabel('Threshold')
            ylabel('w_{min}')
            hold on
            % retreive maximum F1 score and its index
            [max_F1_score, I] = max(F1_score_plot(:));
            [I1, I2] = ind2sub(size(F1_score_plot), I);
            caxis([0 1]);
            % plot dot located at optimal parameters
            scatter(threshold_list(I2), min_window_list(I1), 50, 'filled', 'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'k')
            text(threshold_list(I2), min_window_list(I1), strcat("  ", num2str(max_F1_score, 2)), 'FontSize', 15)
            % format plot axes
            yticks(10:10:40)
            set(gca, 'Position', [0.1758 0.2243 0.6045 0.6835])
            set(gca, 'Fontsize', 13)
            set(gca, 'TickLength', [0.02 0.035])
            set(gca, 'LineWidth', 1.2)
            set(gca, 'TickDir', 'out')
            % save figure as png
            saveas(gcf, strcat(save_folder, titlestr, '.png'));
        end
    end
else
    for i_N = 1:n_N      
        N = N_list(i_N);
        % create meshgrid
        [x_grid, y_grid] = meshgrid(threshold_list, min_window_list);
        figure()
        % retreive F1 score matrix of given i_N
        F1_score_plot = F1_score(:, :, i_N);
        % create contourplot with stepsize 0.005
        contourf(x_grid, y_grid, F1_score_plot, 0:0.05:1);
        % apply colormap
        colormap(flipud(jet))
        % create colorbar
        h = colorbar();
        % set title string depending given i_N
        if i_N == 1
            titlestr = strcat("Single window (N = 1)");   
        else
            titlestr = strcat("Multiple windows (N = ", num2str(N), ")");   
        end
        % set colorbar title
        hl = title(h, 'F1 score', 'FontSize', 13);
        % format plot title and axes
        title_handle = title(titlestr);
        xlabel('Threshold')
        ylabel('w_{min}')
        hold on
        % retreive maximum F1 score and its index
        [max_F1_score, I] = max(F1_score_plot(:));
        [I1, I2] = ind2sub(size(F1_score_plot), I);
        caxis([0 1]);
        % plot dot located at optimal parameters
        scatter(threshold_list(I2), min_window_list(I1), 50, 'filled', 'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'k')
        text(threshold_list(I2), min_window_list(I1), strcat("  ", num2str(max_F1_score, 2)), 'FontSize', 15)
        % format plot axes
        yticks(10:10:40)
        set(gca, 'Position', [0.1758 0.2243 0.6045 0.6835])
        set(gca, 'Fontsize', 13)
        set(gca, 'TickLength', [0.02 0.035])
        set(gca, 'LineWidth', 1.2)
        set(gca, 'TickDir', 'out')
        % save figure as png
        saveas(gcf, strcat(save_folder, titlestr, '.png'));        
    end
end
else
for i_N = 1:n_N

N = N_list(i_N);
% create meshgrid
    [x_grid, y_grid] = meshgrid(threshold_list, min_window_list);
    figure()
   % retreive specificity matrix of given i_N
    specificity_plot = specificity(:,:,i_N);
    % create contourplot with stepsize 0.005
    contourf(x_grid, y_grid, specificity_plot, 0:0.005:1);
    % apply colormap
    colormap(flipud(jet))
    % create colorbar
    h = colorbar();
    % set title string depending given i_N
    if i_N == 1
        titlestr = strcat("Single window (N = 1)");   
    else
        titlestr = strcat("Multiple windows (N = ", num2str(N), ")");   
    end
    % set colorbar title
    hl = title(h, 'Specificity', 'FontSize', 13);
    % format plot title and axes
    title_handle = title(titlestr);
    xlabel('Threshold')
    ylabel('w_{min}')
    hold on
    % retreive maximum specificity and its index
    [max_specificity, I] = max(specificity_plot(:));
    [I1, I2] = ind2sub(size(specificity_plot), I);
    [min_specificity, I] = min(specificity(:));
    caxis([min_specificity 1]);
    % plot dot located at optimal parameters
    scatter(threshold_list(I2), min_window_list(I1), 50, 'filled', 'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'k')
    text(threshold_list(I2), min_window_list(I1), strcat("  ", num2str(max_specificity, 2)), 'FontSize', 15)
    % format plot axes
    yticks(10:10:40)
    set(gca, 'Position', [0.1758 0.2243 0.6045 0.6835])
    set(gca, 'Fontsize', 13)
    set(gca, 'TickLength', [0.02 0.035])
    set(gca, 'LineWidth', 1.2)
    set(gca, 'TickDir', 'out')
    % save figure as png
    saveas(gcf, strcat(save_folder, titlestr, '.png'));
end
end