How to obtain data from editbox using a pushbutton?
1 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
Paulo Silva
2011-8-31
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');
2 个评论
Paulo Silva
2011-8-31
wordsarray is actually a cell not one array, do this:
wordscell = textscan (words, '%s');
nwords=cellfun(@numel,wordscell);
disp (nwords)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!