How can I draw without replacement?

3 ビュー (過去 30 日間)
Mint
Mint 2022 年 1 月 22 日
編集済み: Mint 2022 年 1 月 22 日
I want a 30-by-40 matrix where each element is one of {1,2,3,4,5,6,7,8,9,10,0,0,0,0,0,0,0, 0,0,0} (or values 1 to 10 and the rest zeros). I have N=30, each going through 40 passes. First the first 20 values are to be drawn without replacement, and then the next 20 values without replacement, so that there are 40 draws per N. The values should then be saved in a text file, separated by commas. Thank yor for all suggestions!

採用された回答

Matt J
Matt J 2022 年 1 月 22 日
編集済み: Matt J 2022 年 1 月 22 日
S=[1,2,3,4,5,6,7,8,9,10,0,0,0,0,0,0,0, 0,0,0];
[~,is1]=sort(rand(30,20),2);
[~,is2]=sort(rand(30,20),2);
result=S([is1,is2])
result = 30×40
3 9 0 0 4 10 5 0 8 0 6 0 0 0 0 0 1 0 2 7 10 0 0 6 9 0 0 4 1 0 0 0 3 0 0 4 8 0 9 1 7 2 0 5 10 0 6 0 0 0 0 10 5 0 2 0 3 0 9 4 0 6 7 0 9 0 5 1 0 8 0 3 0 0 4 0 2 0 0 10 0 0 0 0 9 7 3 0 10 8 0 0 6 0 4 10 0 9 0 5 0 7 2 8 0 0 3 0 1 0 5 9 8 3 0 4 0 0 10 1 1 0 2 0 8 9 7 0 0 6 0 4 10 0 0 0 3 5 0 0 8 0 0 5 9 6 3 2 0 0 0 0 0 8 9 7 0 6 0 0 0 0 2 3 4 0 5 10 0 1 0 0 4 0 0 1 0 0 5 10 0 0 7 1 10 9 0 3 4 8 6 0 0 5 0 0 2 0 0 0 10 1 0 3 0 0 0 0 0 0 0 10 0 0 0 0 0 4 0 0 0 6 8 9 1 5 0 3 7 2 4 1 0 0 0 0 2 0 0 9 9 0 0 0 0 0 8 7 0 2 4 0 1 0 5 6 0 3 10 0 0 0 4 0 0 0 7 0 3 0 7 0 5 0 0 9 0 0 8 0 2 6 0 0 0 10 1 0 3 4 0 0 8 10 0 7 6 0 0 2
writematrix(result)
  1 件のコメント
Mint
Mint 2022 年 1 月 22 日
編集済み: Mint 2022 年 1 月 22 日
Thanks, that solves my problem! :)

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by