function [Nbcycles] = CyclesCounter(HSEED, MaxLength, DEBUG_FLAG); N = length(HSEED(1,:)); M = length(HSEED(:,1)); Nbcycles = zeros(MaxLength,1); if MaxLength >= 4; for n = 2:N; for ni = 2:M; if HSEED(ni,n) == 1; ir_n = find(HSEED(1:ni-1,n)~=0); vic_c = find(HSEED(ni,1:n-1)~=0); for i1 = 1:length(vic_c); ic_c = vic_c(i1); vir_ic_c = find(HSEED(:,ic_c)~=0);vir_ic_c = setdiff(vir_ic_c,ni); intersect_4 = intersect(vir_ic_c,ir_n); if ~isempty(intersect_4); Nbcycles(4) = Nbcycles(4) + length(intersect_4); if DEBUG_FLAG; disp([num2str(length(intersect_4)),' cycle(s) in (',num2str(ni),',',num2str(n),')']); end; end; if MaxLength>=6; if n>=3 & ni>=3; % otherwise no cycles of length 6 for i2 = 1:length(vir_ic_c); ir_ic_c = vir_ic_c(i2); vic_ir_ic_c = find(HSEED(ir_ic_c,1:n-1)~=0);vic_ir_ic_c = setdiff(vic_ir_ic_c,[n,ic_c]); for i3 = 1:length(vic_ir_ic_c); ic_ir_ic_c = vic_ir_ic_c(i3); vir6 = find(HSEED(:,ic_ir_ic_c)~=0);vir6 = setdiff(vir6,[ni,ir_ic_c]);% tentative indices for cycles of length 6 intersect_6 = intersect(vir6,ir_n); if ~isempty(intersect_6); Nbcycles(6) = Nbcycles(6) + length(intersect_6); if DEBUG_FLAG; disp([num2str(length(intersect_6)),' cycle(s) in (',num2str(ni),',',num2str(n),')']); end; end; if MaxLength>=8; if n>=4 & ni>=4; % otherwise no cycles of length 8 for i81 = 1:length(vir6); ir_ic_ir_ic_c = vir6(i81); vic_ir_ic_ir_ic_c = find(HSEED(ir_ic_ir_ic_c,1:n-1)~=0);vic_ir_ic_ir_ic_c = setdiff(vic_ir_ic_ir_ic_c,[n,ic_c,ic_ir_ic_c]); for i82 = 1:length(vic_ir_ic_ir_ic_c); ic_ir_ic_ir_ic_c = vic_ir_ic_ir_ic_c(i82); vir8 = find(HSEED(:,ic_ir_ic_ir_ic_c)~=0);vir8 = setdiff(vir8,[ni,ir_ic_c,ir_ic_ir_ic_c]);% tentative indices for cycles of length 8 intersect_8 = intersect(vir8,ir_n); if ~isempty(intersect_8); Nbcycles(8) = Nbcycles(8) + length(intersect_8); if DEBUG_FLAG; disp([num2str(length(intersect_8)),' cycle(s) in (',num2str(ni),',',num2str(n),')']); end; end; if MaxLength>=10; if n>=5 & ni>=5; % otherwise no cycles of length 10 for i101 = 1:length(vir8); ir_ic_ir_ic_ir_ic_c = vir8(i101); vic_ir_ic_ir_ic_ir_ic_c = find(HSEED(ir_ic_ir_ic_ir_ic_c,1:n-1)~=0);vic_ir_ic_ir_ic_ir_ic_c = setdiff(vic_ir_ic_ir_ic_ir_ic_c,[n,ic_c,ic_ir_ic_c,ic_ir_ic_ir_ic_c]); for i102 = 1:length(vic_ir_ic_ir_ic_ir_ic_c); ic_ir_ic_ir_ic_ir_ic_c = vic_ir_ic_ir_ic_ir_ic_c(i102); vir10 = find(HSEED(:,ic_ir_ic_ir_ic_ir_ic_c)~=0);vir10 = setdiff(vir10,[ni,ir_ic_c,ir_ic_ir_ic_c,ir_ic_ir_ic_ir_ic_c]);% tentative indices for cycles of length 10 intersect_10 = intersect(vir10,ir_n); if ~isempty(intersect_10); Nbcycles(10) = Nbcycles(10) + length(intersect_10); if DEBUG_FLAG; disp([num2str(length(intersect_10)),' cycle(s) in (',num2str(ni),',',num2str(n),')']); end; end; if MaxLength>=12; if n>=6 & ni>=6; % otherwise no cycles of length 12 for i121 = 1:length(vir10); ir_ic_ir_ic_ir_ic_ir_ic_c = vir10(i121); vic_ir_ic_ir_ic_ir_ic_ir_ic_c = find(HSEED(ir_ic_ir_ic_ir_ic_ir_ic_c,1:n-1)~=0);vic_ir_ic_ir_ic_ir_ic_ir_ic_c = setdiff(vic_ir_ic_ir_ic_ir_ic_ir_ic_c,[n,ic_c,ic_ir_ic_c,ic_ir_ic_ir_ic_c,ic_ir_ic_ir_ic_ir_ic_c]); for i122 = 1:length(vic_ir_ic_ir_ic_ir_ic_ir_ic_c); ic_ir_ic_ir_ic_ir_ic_ir_ic_c = vic_ir_ic_ir_ic_ir_ic_ir_ic_c(i122); vir12 = find(HSEED(:,ic_ir_ic_ir_ic_ir_ic_ir_ic_c)~=0);vir12 = setdiff(vir12,[ni,ir_ic_c,ir_ic_ir_ic_c,ir_ic_ir_ic_ir_ic_c,ir_ic_ir_ic_ir_ic_ir_ic_c]);% tentative indices for cycles of length 12 intersect_12 = intersect(vir12,ir_n); if ~isempty(intersect_12); Nbcycles(12) = Nbcycles(12) + length(intersect_12); if DEBUG_FLAG; disp([num2str(length(intersect_12)),' cycle(s) in (',num2str(ni),',',num2str(n),')']); end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end; end;