Eliminating and counting rows that contain a pattern that already appeared
Show older comments
Below is my code. What is does is generates all the possible permutations for a number n
, Then it finds all the permutation differences for all of the rows and then takes what would be a n! by n matrix and makes it a n! by 2*n matrix and places the columns 1:n into the columns n+1:2*n. What I want to find is all of the rows that contain the same n length pattern somewhere in the columns. See Below:
function [sigma,A,B] = SigPerm(n)
%create matrix A, the set of all permutations
v = 1:n;
A = perms(v);
%Create matrix B, the set of all permutation differences with one cycle
%added
B = zeros(factorial(n),2*n);
for i = 1:factorial(n)
for t = 1:n-1
B(i,t) = mod(A(i,t+1)-A(i,t),n);
B(i,n) = mod(A(i,1)-A(i,n),n);
end
B(i,n+1:2*n) = B(i,1:n);
end
end
for lets say n = 5, We get a 120x10 matrix. Looking at the first 10 rows:

What I want is to group all the rows that contain unique patterns together. For example, row 1 would be alone, row 2 which has a pattern of [4 4 3 1 3] would group with rows 3, 7, and 10 as all of those rows contain the pattern [4 4 3 1 3] somewhere in their columns. Rows 4 and 5 would group together with the pattern [4 3 4 2 2] and rows 6, 8, and 9 would not group with any of the first 10 rows.
Is there a way I can count how rows contain the pattern and eliminate any rows that repete a pattern that is already present?
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!