Write a matlab code to generate a full deck of cards. Shuffle the deck of cards and pick a card from it. Record whether it was a diamond or not a diamond. Reshuffle the deck and pick a card again and repeat this same procedure 10 times.
14 views (last 30 days)
Show older comments
Write a matlab code to generate a full deck of cards. Shuffle the deck of cards and pick a card from it. Record whether it was a diamond or not a diamond. Reshuffle the deck and pick a card again and repeat this same procedure 10 times. Also repeat the whole procedure for 10 different times (2 for loops). Also generate a number of diamonds vs probability histogram.
%if true
% code
%end
%------ My Code Starts Below -------%
diam = count;
for n = 1:10
for m = 1:10
r = randi([1 4]);
if r == 1
count = count+1;
end
end
diam = count;
end
disp(count)
histogram(diam)**
0 Comments
Answers (1)
Image Analyst
on 28 Feb 2018
A "full deck of cards" is 52 cards, not 4, so you have not done what they told you to do. HINT: Use
r = randperm(52, 1)
Assume that the ID numbers of diamonds are 1 through 13 so you just need to check if r <= 13 (not r==1 as you tried). If it is, it's a diamond. If it's not, it's something else.
You can't use randi() as you did because randi() can have repeats, while randperm() will have no repeats. For example with randi you might have 3 jack of spades, but no queen of hearts. That can't happen with randperm since each and every card is represented once and only once.
If you want full examples (to other problems, not yours), see my Monte Carlo card dealing simulations, attached.
Since it appears to be your homework problem, we can't just solve this simple problem for you outright.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!