how to fix a sequence generated using randperm

I am trying to generate a sequence of numbers using randperm, is there a way I can fix the sequence generated like for example we can use rng for randi.

 採用された回答

Walter Roberson
Walter Roberson 2018 年 6 月 2 日

1 投票

randperm() uses rand() internally, so rng() will work.

3 件のコメント

Foram Sanghavi
Foram Sanghavi 2018 年 6 月 2 日
編集済み: Foram Sanghavi 2018 年 6 月 2 日
I have tried that but it did not work, but it would be great if you could put in a sample code to show what you said, just to be sure if I coded it correctly. Thank you
Walter Roberson
Walter Roberson 2018 年 6 月 2 日
>> rng(55)
>> randperm(18,5)
ans =
14 1 4 15 7
>> rng(55)
>> randperm(18,5)
ans =
14 1 4 15 7
Foram Sanghavi
Foram Sanghavi 2018 年 6 月 2 日
Thank you so much, I was not setting the seed in rng, hence was not getting the same answer.

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by