parameter for geting similar permutation?

1 回表示 (過去 30 日間)
Mahesh
Mahesh 2014 年 8 月 6 日
コメント済み: Mahesh 2014 年 8 月 6 日
I have say n = 10 numbers of data point and I would like to suffle them randomly. Later I would like to get same randomized items through permutation. But I am not able to get that one. If I perform randperm I will get different sets such as k1 and k2 below. k1 = randperm(10)
k1 =
10 5 8 3 1 9 2 6 4 7
>> k2 = randperm(10)
k2 =
1 5 6 7 10 4 9 2 8 3
I would like to get desired set of permuted item in future. Is there any parameter we can define so that they will get same permuted items. In the above example say I would like to get k1 through some parameter. Please let me know how we can define such parameter without saving these sets. It will be great to share such ideas.
Thanks

回答 (2 件)

Roger Stafford
Roger Stafford 2014 年 8 月 6 日
The easiest way to accomplish that would be to use 'randperm' to produce a random permutation, p, of the sequence 1:length(k1) and use that permutation to get from k1 to k2, now and at any time later, provided p is saved.
p = randperm(1:length(k1));
k2 = k1(p);
If you save p, you can always recreate the same k2 from k1.
  1 件のコメント
Mahesh
Mahesh 2014 年 8 月 6 日
Yes off course if you create new data file for p and index as parameter. But it works only for fixed data. If you need to apply, it will not work unless you recreate another data file. Am I right??

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


Star Strider
Star Strider 2014 年 8 月 6 日
You need to control the random number generator to do what you want. See the documentation on rng, specifically the section to Generate Random Numbers That Are Repeatable.

カテゴリ

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