Rotating rows until they align with a row above in a matrix
Show older comments
I have a i by n matrix. The matrix contains all the unique permutations of 1:n. I want this code to go through each row and rotate the row and compare it with the rows above to see if it matches any of them, if not, I want it to rotate again, until it has either rotated n times or it finds a match. Right now what I have is
for i = 1:size(D,1)
if D(i,n+1) == 1
else
for t = i+1:size(B,1)
if D(i,1:n) == D(t,1:n)
continue
else
D(i,1:n) = circshift(D(i,1:n),1);
end
end
end
end
Where the matrix D is our i by n matrix. The problem is, this only rotates a row one time if it does not find a match, and then it moves on to the next row. I am not sure if I need to use a while loop or something? I will take any advise you have.
Thank you.
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!