function [subsetaveragewithin_between] = subset_aver_within_versus_between(n,k)

% SUBSET_AVER_WITHIN_VERSUS_BETWEEN produces a symmetric proximity matrix of size $n
% \times n$ that contains all zeros except for the $k \times k$
% upper-left-hand block (those off-diagonal entries are $1/(k*(k-1))$, to
% produce an average subset proximity value in a second matrix), and the 
% upper-left-hand ($k \times (n-k)$) and lower-right-hand ($(n-k) \times k$) corners 
% (these values are $-1/(2*k*(n-k))$ to "take away" a between subset average).
%
% syntax: [subsetaveragewithin_between] = subset_aver_within_versus_between(n,k)

subsetaveragewithin_between = zeros(n,n);

for i = 1:k
    for j = 1:k
        
        if (i ~= j)
        
        subsetaveragewithin_between(i,j) = 1/(k*(k-1));
        
        end
        
    end
end

for i = 1:k
    for j = (k+1):n
        
        subsetaveragewithin_between(i,j) = -1/(2*k*(n-k));
        subsetaveragewithin_between(j,i) = -1/(2*k*(n-k));
        
    end
end