You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: arPlotFits.m
    path of file: ./repos/d2d/arFramework3
    
    the code of the file until where you have to start completion: % arPlotFits(q_select, i_fits)
% 
% Plot results of multistart optimization. This function is intended to be used after arFitLHS or arFits.
% 
% q_select  [ar.qFit == 1]     which parameters are plotted against each other.
% i_fits    [1:size(ar.ps,1)]  which fits are analyzed 
% 
% This function plots three figures visualizing results of multistart
% optimization:
% figure 1: overview about likelihood values before and after the
% multistart optimization. Waterfall plot.
% figure 2: histogram of run time, histogram of function evaluations and
% plot of gradient length.
% figure 3: scatter plots of parameter values (q_select) in the i_fits.

function arPlotFits(q_select, i_fits)

global ar

if(~exist('q_select','var'))
    q_select = ar.qFit==1;
end
if(~exist('i_fits','var'))
    i_fits = 1:size(ar.ps,1);
end

%% chi^2 plots

chi2constr = ar.chi2s + ar.chi2sconstr;
chi2constr_start = ar.ch
    
function value', 'Location','Best');


figure(2); clf;
subplot(2,2,1);
hist(ar.timing, 50);
xlabel('time / sec / fit');
title({sprintf('run time for %i fits', ...
    sum(~isnan(ar.timing)))
    sprintf('(cumulative time: %s)', ...
    secToHMS(sum(ar.timing(~isnan(ar.timing)))))});

subplot(2,2,2);
hist(ar.fun_evals, 50);
xlabel('number of function evaluations / fit');
title({sprintf('number of function evaluations for %i fits', ...
    sum(~isnan(ar.fun_evals)))
    sprintf('(cumulative number: %i)', ...
    sum(ar.fun_evals(~isnan(ar.fun_evals))))});

subplot(2,2,[3 4]);
semilogy(optim_krit, 'o--');
xlabel('run index (sorted by likelihood)');
ylabel('gradient length');
title('first order optimality criterion');
set(gcf,'Position',get(gcf,'Position')+[pos1(3),0,0,0]); %shift horizontal position by the horizontal width of the 1st figure

%% scatter plots

nji = sum(q_select);
if(nji < 6)
    figure(3);
    
    ji = find(q_select);
    scount = 1;
    for j1 = 1:nji
        for j2 = 1:nji
            if(j1>j2)
                subplot(nji,nji,scount);
                plot(ar.ps_start_sorted(i_fits,ji(j2)), ar.ps_start_sorted(i_fits,ji(j1)), 'ro');
                hold on
                for jn = i_fits
                    plot([ar.ps_start_sorted(jn,ji(j2)) ar.ps_sorted(jn,ji(j2))], ...
                        [ar.ps_start_sorted(jn,ji(j1)) ar.ps_sorted(jn,ji(j1))], '--', 'Color', [.8 .8 .8]);
                    
                end