% function [R] = getRow(i, n)
% Given an index i on a vector of distances computed by the pdist function,
% and the number n of data whose mutual distances have been stored in the
% vector, getRow returns the set of indexes corresponding to distance
% values involving i. In other words, this corresponds to extracting the
% i-th row from the 2D matricial representation of the distance vector.
%
% This file is part of Cluster4MetaAnalysis.
%     Cluster4MetaAnalysis is free software: you can redistribute it 
%     and/or modify it under the terms of the GNU General Public License 
%     as published by the Free Software Foundation, either version 3 of 
%     the License, or (at your option) any later version.
% 
%     Cluster4MetaAnalysis is distributed in the hope that it will be 
%     useful, but WITHOUT ANY WARRANTY; without even the implied warranty 
%     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with Cluster4MetaAnalysis.  If not, see
%     <http://www.gnu.org/licenses/>.


function [R] = getRow(i, n)

I1 = 1:(i-1);
I2 = (i+1):n;

% indexes for pairs i,j with j<i
R1 = I1.*(n - (I1+1)/2) + i - n;

% indexes for pairs i,j with i<j
R2 = i*(n - (i+1)/2) + I2 - n;

R = [R1 R2];
