フィルターのクリア

Randomly pair two sets of integers, without repeating the first set?

2 ビュー (過去 30 日間)
Amos Tan
Amos Tan 2017 年 10 月 13 日
コメント済み: Amos Tan 2017 年 10 月 13 日
I have two sets of integers, Set 1: (1,2,3,...,32) and Set 2: (33,34,35,...,40). That is, Set 1 has 32 items and Set 2 has 8 items.
I would like to pair the items in Set 1 to those in Set 2, such at each item in Set 1 is randomly paired to any of the 8 items in Set 2. This means the items in Set 2 can be repeated, but items in Set 1 are not repeated. And I want them to be paired in a random sequence as well.
Example: 3 paired with 35, 30 paired with 33, 18 paired with 40, 10 paired with 33 (33 can be repeated), etc... until a random sequence is generated where all 32 items in Set 1 are paired.
How can I do this? I know I should be using randperm somewhere.
Thank you so much in advance!

採用された回答

Roger Stafford
Roger Stafford 2017 年 10 月 13 日
編集済み: Roger Stafford 2017 年 10 月 13 日
M = [reshape(set1(randperm(32)),[],1),set2(randi(8,32,1))];
  1 件のコメント
Amos Tan
Amos Tan 2017 年 10 月 13 日
thank you, sir, although for some reason I had to remove the "set1" and "set2" and their accompanying parentheses for it to work.
now I would like to create 50 of such sequences, and save them as separate variables. could you tell me how to do it? I think you have to use looping (for... end)?
thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by