MATLAB: How to make a string entered in an “Edit Text” box become a variable

guistringstext;

I'm trying to make a game of some sort where one part involves typing in text in an "edit text" box, and another user typing in text in another "edit text" box. In short, if the text matches, the 2nd player wins the game.
Right now, I'm having trouble trying to figure out how to get the string in the "Edit Text" box to be recognized as a variable from which it will be easy to compare other strings to.
What I've tried:
function GueText_CreateFcn(hObject, eventdata, handles) % hObject handle to GueText (see GCBO) % eventdata reserved – to be defined in a future version of MATLAB % handles empty – handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
B = get(GueText,'String');
Which doesn't work. I think I'm not using the "get" command properly and am not entering the proper handle.
Any ideas? Thanks for any help you can provide.

Best Answer

Here is one example that shows the process of manipulating data from edit boxes.
function [] = gui_edits()
% How to use strings from edit boxes.
S.fh = figure('name','editbox game',...
'menubar','none',...
'numbert','off',...
'pos',[100 100 300 150]);
S.ed(1) = uicontrol('Style','edit',...
'Units','pix',...
'Position',[10 10 130 130],...
'CallBack',@callb,...
'String','Player 1');
S.ed(2) = uicontrol('Style','edit',...
'Units','pix',...
'Position',[150 10 130 130],...
'CallBack',@callb,...
'String','Player 2');
movegui('center')
S.P1 = '';
S.P2 = '';
guidata(S.fh,S) % Store the structure.
uicontrol(S.ed(1)) % put the focus on player 1s box.
function [] = callb(varargin)
% Callback for the edit boxes
S = guidata(gcbf); % Get the structure.
if gcbo==S.ed(1) % If player 1 called.
S.P1 = get(S.ed(1),'string'); % Store the string!
set(S.ed(1),'string','Waiting for Player 2!')
uicontrol(S.ed(2)) % Put focus on player 2.
else
TF = strcmp(S.P1,get(S.ed(2),'string'));
if TF
set(S.ed,'string','Player 2 wins!')
else
set(S.ed,'string','Player 1 wins!')
end
end
guidata(S.fh,S)