How to test if two elements in a vector are of the same value.

9 views (last 30 days)
I am trying to find where two elements of a vector share the same value. As well as put it through an if statement to change different things in my poker GUI (which checks your hand and the river to tell you what hand exists on the table). My matlab skills are basic so some explanation would be helpful!
for i=1:7
box(i)=0
end
box(1)=str2double(get(handles.edit1,'string'));
%Continues to fill to the element of box(7)
box(7)=str2double(get(handles.edit7,'string'));
box=sort(box);
%Say that box=[1 1 3 8 9 11 12]
if box(1)==box(2)
set(handles.Hand,'string','One Pair')
end

Accepted Answer

Kevin Rawson
Kevin Rawson on 13 Apr 2019
Edited: Kevin Rawson on 13 Apr 2019
If we assume you are using numbers 1 through 14 to represent the face value of the cards (neglecting joker), then:
cardCounts = histc(box, 1:14);
This counts the number of cards with a given face value (from 1 to 14) that exist in box.
Then if you take the sum(cardCounts == 2), you know how many single pairs you have.

More Answers (1)

Image Analyst
Image Analyst on 13 Apr 2019
You might be interested in my attached poker app where I compute the probability of the major hands of poker using a Monte Carlo approach.
Found 422410 "One Pair" in 1000000 hands. That is one in every 2 hands.
Percentage of "One Pair" = 42.241000%. Theory says 42.2569%
Found 47995 "Two Pairs" in 1000000 hands. That is one in every 21 hands.
Percentage of "Two Pairs" = 4.799500%. Theory says 4.7539%
Found 20894 "3 of a kind" in 1000000 hands. That is one in every 48 hands.
Percentage of "3 of a kind" = 2.089400%. Theory says 2.1128%
Found 3689 straights in 1000000 hands. That is one in every 271 hands.
Percentage of straights = 0.368900%. Theory says 0.3925%
Found 1870 Flushes (excluding straight and royal) in 1000000 hands. That is one in every 535 hands.
Percentage of Flushes = 0.187000%. Theory says 0.1956%
Found 1427 Full Houses in 1000000 hands. That is one in every 701 hands.
Percentage of Full Houses = 0.142700%. Theory says 0.1441%
Found 247 "4 of a kind" in 1000000 hands. That is one in every 4049 hands.
Percentage of "4 of a kind" = 0.024700%. Theory says 0.0240%
Found 11 straight flushes (excluding royal) in 1000000 hands. That is one in every 90909 hands.
Percentage of straight flushes = 0.001100%. Theory says 0.00139%.
Found 2 Royal Flushes in 1000000 hands. That is one in every 500000 hands.
Percentage of Royal Flushes = 0.000200%. Theory says 0.000154%
See attached m-file. Adapt as needed.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!