MATLAB: Test poker hand by using edit text boxes GUI

guiif statementMATLAB and Simulink Student Suitematlab gui

For a project for my engineering class we are supposed to make a helper to any game. I chose poker and I am having trouble simplifying the conditions such that I do not have to test every possible hand manually. In my function I call get the string of the text boxes (Ace=1,King=2,Queen=3, etc.). I need help on testing the conditions (what card they are) of the edit text boxes and displaying the correct hand output. If more information is needed please let me know!
function pushbutton2_Callback(hObject, eventdata, handles)
box1=str2double(get(handles.edit1,'string'));
box2=str2double(get(handles.edit2,'string'));
box3=str2double(get(handles.edit3,'string'));
box4=str2double(get(handles.edit4,'string'));
box5=str2double(get(handles.edit5,'string'));
box6=str2double(get(handles.edit6,'string'));
box7=str2double(get(handles.edit7,'string'));
if box1==1 && box2==2 && box3==3 && box6==4 && box7==5
set(handles.Hand,'string','Royal Flush')

Best Answer

What I would do is first of all change your value convention to something more standard (Ace=1,Jack=11,Queen=12,King=13) or keep them in a char format. Having an array of handles instead of numbered ones really helps to simplifies your code. Then I would sort the numbers. Because the order doesn't matter, the user can input different orders and you can describe entire vectors at a time.
%if you're using GUIDE (which you shouldn't), you can use this in the startup:
%for n=1:7
% handles.card_input(n)=handles.(sprintf('edit%d',n));
%end
function pushbutton2_Callback(hObject, eventdata, handles)
box=zeros(1,numel(handles.card_input));
for n=1:numel(box)
box(n)=str2double(get(handles.card_input(n),'string'));
end
box=sort(box);
if isequal(box,[1 10 11 12 13])
name='Royal Flush';
elseif numel(unique(box))==2
name='full house'
elseif all(diff(box)==1)
name='straight';
else
name='high card';%default option
end
set(handles.Hand,'String',name)
end
You can add very complicated tests to find all named hands.