How can i plot both hands in a way that shows me the probabilities related to pulling cards?
古いコメントを表示
fullDeck = ["AS",'2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AH','2H','3H','4H','5H','6H','7H','8H','9H','10H','JH','QH','KH','AD','2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AC','2C','3C','4C','5C','6C','7C','8C','9C','10C','JC','QC','KC',]
matlabHand = []
personalHand = []
for i = 1:1000
idx = randi([1 52], 1)
matlabHand = [fullDeck(idx); matlabHand]
end
for i = 1:30
idx = randi([1 52], 1)
personalHand = [fullDeck(idx); personalHand]
end
4 件のコメント
Voss
2023 年 10 月 4 日
I don't understand the question, but note that this code allows drawing the same card multiple times. To constrain to draw any card at most one time, consider using randperm.
Image Analyst
2023 年 10 月 5 日
What do you mean by "plot"? What would be your x and what would be your y?
Angel
2023 年 10 月 5 日
Angel
2023 年 10 月 5 日
回答 (1 件)
Would this work for you?
numbering = ["A",string(2:10), "J", "Q", "K"];
shape = ["S"; "H"; "D"; "C"];
fullDeck = reshape(transpose(numbering + shape), 1, []);
% random sampling with replacement
matlabHand = randi(52, 1, 1000);
personalHand = randi(52, 1, 30);
C1 = hist(matlabHand, 1:52);
C2 = hist(personalHand, 1:52);
%%
figure('position', [500, 500, 1200, 500]);
subplot(2, 1, 1);
scatter(1:52, C1, 30, 'filled')
xticks(1:52)
xticklabels(fullDeck)
xlim([0, 53]);
ylim([0, max(C1)])
ylabel('Frequency');
xlabel('Deck Names');
grid on;
title('MATLAB hand')
subplot(2, 1, 2);
scatter(1:52, C2, 30, 'filled')
xticks(1:52)
xticklabels(fullDeck)
xlim([0, 53]);
ylim([0, max(C1)])
ylabel('Frequency');
xlabel('Deck Names');
grid on;
title('personal hand')
2 件のコメント
Angel
2023 年 10 月 6 日
カテゴリ
ヘルプ センター および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
