function [bands, an, bandaver1, bandaver2] = freqbandaver(PDC1, PDC2, freq, E, r, c, bands, an)

if isempty(bands)
    disp('Do you want to input a frequency band over which to calculate the average PDC? -> 1')
    disp('Or you prefer to use the default bands (0-1;1-4;4-8;8-12;12-24;24-max(frequency))? -> 2')
    an = input('1 or 2?: ');

    if an == 1
        disp('Input the bands of frequencies over which, you wish to calculate the average PDC.')
        disp('(Note that the band limits must correspond to frequencies over which PDC has been calculated!)')
        bands = input('Use a column metrix. (E.G. ~ [0 10; 10 20; 20 30]): ');
        if size(bands,2)~=2
            error('The bands were not given correctly')
        end
    elseif an == 2
        if max(freq) < 24
            error('The frequencies that have been used are lower than some bands!')
        end
        bands = [0 1; 1 4; 4 8; 8 12; 12 24; 24 max(freq)];
    else
        disp('Your choise is not valid. This process will be skipped!')
        return
    end
end

b = size(bands,1);
bandaver1 = zeros(b,E);
bandaver2 = zeros(b,E);

for i=1:b
    ind = [find(freq==bands(i,1)), find(freq==bands(i,2))];
    if length(ind) < 2
        error('Some frequency band limits were not found in the frequency domain used so far!')
    end
    bandaver1(i,:) = mean(PDC1(ind(1):ind(2),:));
    bandaver2(i,:) = mean(PDC2(ind(1):ind(2),:));
end

if an == 2
    disp(['The PDC (', num2str(r), ' > ', num2str(c), ') averages, over frequency bands 0-1Hz; 1-4Hz; 4-8Hz; 8-12Hz (delta, theta, alpha); 12-24Hz (beta);  24-',num2str(max(freq)),'Hz (low gamma) are:']);
    disp(num2str(bandaver2));
    disp(' ')

    disp(['The PDC (', num2str(c), ' > ', num2str(r), ') averages, over frequency bands 0-1Hz; 1-4Hz; 4-8Hz; 8-12Hz; 12-24Hz; 24-',num2str(max(freq)),'Hz, are:']);
    disp(num2str(bandaver1));
    disp(' ')
else
    disp(['The PDC (', num2str(r), ' > ', num2str(c), ') averages, over the user-specified frequency bands are:']);
    disp(num2str(bandaver2));
    disp(' ')

    disp(['The PDC (', num2str(c), ' > ', num2str(r), ') averages, over the user-specified frequency bands are:']);
    disp(num2str(bandaver1));
    disp(' ')
end
