How I can change this multi-loop to reduce the computation time?
A
is a matrix (5 × 10000) where the fifth line contains values between 1 and 50 corresponding to different events of an experiment. My goal is to find the columns of the matrix which are the same for all possible combinations of 7 different events.
data = A(1:4,:);
exptEvents = A(5,:);
% Find repeats
[b,i,j] = unique(data', 'rows');
% Organize the indices of the repeated columns into a cell array
reps = arrayfun(@(x) find(j==x), 1:length(i), 'UniformOutput', false);
% Find events corresponding to these repeats
reps_Events = cellfun(@(x) exptEvents(x), reps, 'UniformOutput', false);
U = cellfun(@unique, reps_Events, 'UniformOutput', false);
repeat_counts = cellfun(@length, U);
kk=1;
for i1=1:50
for i2=1:50
for i3=1:50
for i4=1:50
for i5=1:50
for i6=1:50
for i7=1:50
if i1~=i2 && i2~=i3 && i3~=i4 && i4~=i5 && i5~=i6 && i6~=i7
myEvents = [i1 i2 i3 i4 i5 i6 i7];
v= b(cellfun(@(x)all(ismember(myEvents,x)),U),:);
intersection(1,kk)=v(1);
intersection(2,kk)=v(2);
intersection(3,kk)=v(3);
intersection(4,kk)=v(4);
intersection(5,kk)=i1;
intersection(6,kk)=i2;
intersection(7,kk)=i3;
intersection(8,kk)=i4;
intersection(9,kk)=i5;
intersection(10,kk)=i6;
intersection(11,kk)=i7;
kk=kk+1;
end
end
end
end
end
end
end
end
A
contain a cell for each column, each with 7 values (1-50) in it? \$\endgroup\$