New User: Displaying only intersections between two sets of permutations
in MatLab
Being supplied two strings, 'goosegun' and 'goslingnun', I am to find
every permutation of pick 3 of each string, then display only the
intersections between the two. Currently I am doing this without using
intersect(comboPerm1,comboPerm2,'rows), but I want to know how to use it.
I guess my main problem is figuring out how to display the text.
Here is my code that works (I think).
% Goes through each combination
for i = 1 : numCombos1
comboPerm1 = perms(letterCombos1(i,:));
% Goes through each permutation of the combination
for j = 1 : numPerms
for k = 1 : numCombos2
comboPerm2 = perms(letterCombos2(k,:));
for p = 1 : numPerms
if (comboPerm1(j,:) == comboPerm2(p,:))
counter = counter + 1;
if (mod(counter,numPerms) == 0)
fprintf('\n\t');
end
fprintf('%s ',comboPerm2(p,:));
end
end
end
end
end
Here is my code that I'm trying to use intersect in.
for i = 1 : numCombos1
comboPerm1 = perms(letterCombos1(i,:));
for j = 1 : numPerms
for k = 1 : numCombos2
comboPerm2 = perms(letterCombos2(k,:));
for p = 1 : numPerms
a = intersect(comboPerm1,comboPerm2,'rows');
if (exist(a, 'var') == 0)
fprintf('%s ',a);
end
end
end
end
end
Hope I explained myself well because this is my first question on this
site. Thanks for your help.
No comments:
Post a Comment