MATLAB: How to test if two elements in a vector are of the same value.

arrayguiif statementMATLABvector

I am trying to find where two elements of a vector share the same value. As well as put it through an if statement to change different things in my poker GUI (which checks your hand and the river to tell you what hand exists on the table). My matlab skills are basic so some explanation would be helpful!
for i=1:7
box(i)=0
end
box(1)=str2double(get(handles.edit1,'string'));
%Continues to fill to the element of box(7)
box(7)=str2double(get(handles.edit7,'string'));
box=sort(box);
%Say that box=[1 1 3 8 9 11 12]
if box(1)==box(2)
set(handles.Hand,'string','One Pair')
end

Best Answer

If we assume you are using numbers 1 through 14 to represent the face value of the cards (neglecting joker), then:
cardCounts = histc(box, 1:14);
This counts the number of cards with a given face value (from 1 to 14) that exist in box.
Then if you take the sum(cardCounts == 2), you know how many single pairs you have.