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!
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!