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 CenterFile Exchange에서 Windows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by