Identification/filtering of characters within cell arrays
2 views (last 30 days)
Show older comments
Say you have a cell array:
cell_array={'Kh','8h','8d','Ks','Ac'}
where h=hearts, d=diamonds, s=spades, c=club, K=king, A=ace. In poker, the given combination would correspond to two pairs (and a high card [an ace]).
How do I make sure that two pairs are identified (uniquely), and not as, for instance, a pair or a full house?
As of now, I identify a full house by using:
value1 = cellfun(@(x)x(1),cell_array,'un',0);
[a,b,b] = unique(value1);
i1 = histc(b,1:max(b));
t = ismember(a,'K');
out = all(i1(t) == 3 & i1(~t) == 2);
as proposed by Andrei Brobov.
But how do I apply rules such that two pairs identified, and not, for instance, a pair or a full house?
With the code above, one sees that if "i1(t) == 3" is exchanged to "i1(t) == 2", then an additional argument for the high card (in this case the ace A) is required to make sure that a full house is actually not present. But the (t) and (~t) only allows for two conditions - I need three!
0 Comments
Accepted Answer
Walter Roberson
on 7 Jul 2012
any(i1 == 3) & any(i1 == 2) %full house
sum(i1 == 2) == 2 %two pair
0 Comments
More Answers (0)
See Also
Categories
Find more on Windows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!