MATLAB: GUI problem with code

guitictactoe

Code not working

Best Answer

Neha - without your figure file, we cannot run the GUI and so cannot step through the code (with the debugger) to see what is happening...or observe any errors in the console. Have you seen any errors and, if so, what are they?

Looking at your buttonPress function, I noticed the following

if get(handles.whoseTurn, 'String') == 'x'
    set(hObject,'String') = 'x';
    set(handles.whoseTurn, 'String') = 'o';
else
    set(hObject,'String') = 'o'
    set(handles.whoseTurn,'String') = 'x' ;
    %still need to update turn information data
end

When comparing strings, the == will generally fail when your strings are of different lengths and so you will see an error like

Error using  == 
Matrix dimensions must agree.

To avoid this, use strcmp or strcmpi as

if strcmpi(get(handles.whoseTurn, 'String'), 'x')
   % do something
else
   % do something else
end

And, when setting the (edit) text control, you need to pass in the value rather than using the assignment operator =. So the line

set(hObject,'String') = 'x';

which will generate an error, should become

set(hObject,'String', 'x');

Please try fixing these bugs and re-run your code. If you observe any further errors, please copy and paste the full error message (the red text) to this question.