Identification/filtering of characters within cell arrays

3 ビュー (過去 30 日間)
Ole Hansen
Ole Hansen 2012 年 7 月 7 日
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 Center および File ExchangeWindows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by