Identification/filtering of characters within cell arrays

2 次查看(过去 30 天)
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!

采纳的回答

Walter Roberson
Walter Roberson 2012-7-7
any(i1 == 3) & any(i1 == 2) %full house
sum(i1 == 2) == 2 %two pair

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Card games 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by