[m,indexmatrix] = Find_indexmatrix(n) Find_indexmatrix: Given a number of variables, creates a structure that associates an index to every possible edge of a full structure (all related variables) INPUTS n: Number of variables OUTPUTS m: Number of variables indexmatrix: Matrix where entry i,j has the associated index of edge i,j. Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)
0001 function[m,indexmatrix] = Find_indexmatrix(n) 0002 % [m,indexmatrix] = Find_indexmatrix(n) 0003 % Find_indexmatrix: Given a number of variables, creates a structure that 0004 % associates an index to every possible edge of a full structure (all related 0005 % variables) 0006 % INPUTS 0007 % n: Number of variables 0008 % OUTPUTS 0009 % m: Number of variables 0010 % indexmatrix: Matrix where entry i,j has the associated index of edge i,j. 0011 % 0012 % Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es) 0013 0014 0015 m = n*(n+1)/2; % Number of possible edges 0016 0017 indexmatrix = zeros(n,n); % Matrix of indices for edges 0018 a= 1; 0019 for i=1:n-1 0020 for j=i+1:n 0021 indexmatrix(i,j) = a; % Each edge has an associated index 0022 indexmatrix(j,i) = a; 0023 a = a + 1; 0024 end 0025 end