Plotting the probability of drawing a Spade

3 views (last 30 days)
Cole Kleinow on 14 Feb 2021
Answered: Vimal Rathod on 19 Feb 2021
so i need to plot the probability of drawing a spade out of 100 draws (card replaced each time) but i cant quite figure out what to math against what
Deck = [];
Hearts = 0;
Diamonds = 0;
Clubs = 0;
n = 100;
Drawn = [];
for rank = 1:13
for suit = 1:4
cardval = [rank suit];
Deck = [Deck, {cardval}];
end
end
for tries = 1:n
Shuffled = Deck(randperm(length(Deck)));
Card = Shuffled(1,1);
Drawn = [Drawn,Card];
if Card{1}(2) == 1
Hearts = Hearts + 1;
elseif Card{1}(2) == 2
elseif Card{1}(2) == 3
Diamonds = Diamonds + 1;
else
Clubs = Clubs + 1;
end
end
SuitsDrawn = [Hearts Spades Diamonds Clubs];
grandTotalSum = sum(counts(:));
normalizedCountSums = counts / grandTotalSum;
plot(edges, normalizedCountSums)
Cris LaPierre on 15 Feb 2021
How many cards are in a deck? How many of those cards are spades?

Vimal Rathod on 19 Feb 2021
Hi,
Probability of drawing spades from 100 draws is still one single value. You can try adding a for loop over the for loop with tries. This way you will get many values of probability of drawing spades from 100 draws. Then you could plot all those points by saving the edges and normalizedCountSums as arrays.
% getting 10 different probability values for
% probability of drawing spades from 100 draws
for set = 1:10
for tries = 1:n
end
% finding edges and NormalizedCountSums
%concatenate the edges and normalizedCountSums
..
..
end
Hope this helps!

R2020b

Community Treasure Hunt

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

Start Hunting!