Если я создаю случайную матрицу packets
:
N = 50 %size of the packets matrice
packets = round(rand(N,N)); %random matrice
comb = nchoosek(1:N,3); %all combination without permutation
combrow = perms(1:3); %permutation for dimension 3
comb = reshape(comb(:,combrow),[],3); %all combination with permutation
f1 = find(packets(sub2ind([N,N],comb(:,1),comb(:,2)))>0); %check condition 1
f2 = find(packets(sub2ind([N,N],comb(:,1),comb(:,3)))>0); %check condition 2
ind = ismember(f1,f2); %check condition 1&&2
cwp = comb(f1(ind),:); %get the result
Это должно быть намного быстрее, чем решение для цикла.
Этот алгоритм производит (N-2)*(N-1)*(N)
комбинаций (как объясненоАндер Бигури, это почти O (N ^ 3)), поэтому для больших N он будет занимать много памяти.