Sorting Permutation Matrix for Rows With Specific Consecutive Values

1 次查看(过去 30 天)
This code:
n = 3;
v = [1:n 1:n 1:n];
P = nchoosek(v,3);
A = unique(P,'rows');
Produces a Matrix of unique permutations of 1,2 & 3. eg.
1 1 1
1 2 1
1 2 2
1 3 3
etc
I want to sort the resulting rows, eliminating rows with any number of consecutive ones and twos, but NOT consecutive 3's. So in this example (composed of 4 of the 27 rows of A) rows 1 and 3 are no go's but 2 and 4 are fine. I experimented with 'diff(X,n,dim)' but couldn't find an elegant solution.
Thanks in advance.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by