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: rindex.m
    path of file: ./repos/fieldtrip/external/icasso
    
    the code of the file until where you have to start completion: function ri=rindex(dist,partition)
%function ri=rindex(dist,partition)
%
%PURPOSE
%
%To compute a clustering validity index called R-index to assist in
%selecting a proper number of clusters. Input argument
%'partition' defines different clustering results, partitions, of
%the same data. Clustering result that has a (local) minimum value for
%R-index among the compared ones is a "good" one.     
%

    
function ri=rindex(dist,partition)
%function ri=rindex(dist,partition)
%
%PURPOSE
%
%To compute a clustering validity index called R-index to assist in
%selecting a proper number of clusters. Input argument
%'partition' defines different clustering results, partitions, of
%the same data. Clustering result that has a (local) minimum value for
%R-index among the compared ones is a "good" one.     
%
%The index is not computed (NaN) if the partition contains a
%cluster consisting of only one item.
%
%INPUT
%
% dist      (NxN matrix) matrix of pairwise dissimilarities between N objects
% partition (KxN matrix) K partition vectors of the same N objects (see
%            explanation for 'partition vector' in function hcluster) 
%
%OUTPUT
%
% ri (Kx1 vector) ri(k) is the value of R-index for clustering
%      given in partition(k,:).
%
%DETAILS
%
%R-index is a Davies-Bouldin type relative clustering validity
%index. The clustering that has the minimum value among is the best
%in terms of R-index. The index is originally defined in Levine &
%Dormay (2001),  "Resampling method for unsupervised estimation of
%cluster validity. Neural Computation, and redescribed in
%publication Himberg et al. (2004), "Validating the independ