Remove duplicates from array for landmark sequence generation

2 ビュー (過去 30 日間)
Isuru
Isuru 2014 年 6 月 2 日
コメント済み: Henric Rydén 2014 年 6 月 2 日
Hi,
Say I had an array:
x
I have 6 landmarks and I want to generate different path ways so I travel each landmarks once;
For example;
I want x to look like;
x = [1 2 3 4 5 6] or x = [1 3 2 5 4 6] or x = [1 5 4 2 3 6] without any repetition of landmarks.
However 1 is the starting landmark and 6 is the end landmark. I want these to stay as it is. The landmarks between are generated using randperm(6). How do generate an array like this?
Thanks
  1 件のコメント
pietro
pietro 2014 年 6 月 2 日
May you prepare an example with the wished result, please?

サインインしてコメントする。

回答 (1 件)

Henric Rydén
Henric Rydén 2014 年 6 月 2 日
perms(x(2:end-1))
gives you all paths. Add ones and sixes with
[repmat(1,factorial(4),1) perms(x(2:end-1)) repmat(6,factorial(4),1)]
  2 件のコメント
Isuru
Isuru 2014 年 6 月 2 日
Thanks for the reply. This still gives me repeated landmark values. So I only want to visit each landmark once from start to end and can't visit one place twice. Is there another way around this?
Henric Rydén
Henric Rydén 2014 年 6 月 2 日
What do you mean by "repeated landmark values"? All rows in the output contains 1-6 and are never repeated.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by