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: CBIG_ComputeClusterStability.m
    path of file: ./repos/CBIG/utilities/matlab/parcellation
    
    the code of the file until where you have to start completion: function stability = CBIG_ComputeClusterStability(labels)

% stability = CBIG_ComputeClusterStability(labels)
% 
% Compute how stable the parcellation labels are in multiple trials.
% Stability is defined by Dice overlap.
%
% assume labels are num_vertices x # trials
%
% Written by CBIG under MIT license: https://github.com/ThomasYeoLab/CBIG/blob/master/LICENSE.md


    
function stability = CBIG_ComputeClusterStability(labels)

% stability = CBIG_ComputeClusterStability(labels)
% 
% Compute how stable the parcellation labels are in multiple trials.
% Stability is defined by Dice overlap.
%
% assume labels are num_vertices x # trials
%
% Written by CBIG under MIT license: https://github.com/ThomasYeoLab/CBIG/blob/master/LICENSE.md



N = size(labels, 1);
T = size(labels, 2);
K = max(labels(:, 1));
stability = zeros(N, 1);

tic
dice_mat = zeros(K, K, T);
for t = 1:T % foreach reference
       
    disp(num2str(t)); 
    
    ref_labels = labels(:, t);
    for i = 1:K
        ref_vec = double(ref_labels == i);  
        for j = 1:K
            neighbors = double(labels == j);
            innerprod = sum(bsxfun(@times, neighbors, ref_vec), 1);
            dice_mat(i, j, :) = 2*innerprod./(sum(neighbors, 1) + sum(ref_vec));
        end