Sorting Permutation Matrix for Rows With Specific Consecutive Values

2 visualizaciones (últimos 30 días)
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.

Respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by