% function [i1 i2] = getMatrixIndexes(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, getMatrixIndexes returns the two indexes corresponding to
% 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 [i1 i2] = getMatrixIndexes(i, n)

i1 = floor(n + 1/2 - sqrt(n^2 - n + 1/4 - 2 * (i - 1)));
i2 = i - (i1 - 1) * (n - i1/2) + i1;