MATLAB: How to obtain data from editbox using a pushbutton

function handlegui

Hi all, My GUI (called tts2) has an editbox and a pushbutton. By pushing the button, the pushbutton callback is supposed to scan the editbox and return the number of words written. But i'm not sure how to code the pushbutton callback to obtain the data it needs from the editbox function. Here's the code for the callback sections of the editbox and pushbutton:
function tts2_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
function varargout = tts2_OutputFcn(hObject, eventdata, handles) ;
varargout{1} = handles.output;
function editbox_Callback(hObject, eventdata, handles)
function editbox_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pushbutton1_Callback(hObject, eventdata, handles)
words = get(hObject, 'string');
wordsarray = textscan (words, '%s');
max_words = length(wordsarray)
disp (wordsarray)

Best Answer

words = get(handles.edit, 'String'); %edit is the name of the edit box
if you are using GUIDE the names of the editboxes are done consecutively (edit1,edit2,edit3...) so if you only have one editbox the name is edit1 unless you changed it.
words = get(handles.edit1, 'String');