Sorting Permutation Matrix for Rows With Specific Consecutive Values

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 件)

カテゴリ

ヘルプ センター および File ExchangeDescriptive Statistics についてさらに検索

質問済み:

2015 年 11 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by