How to obtain data from editbox using a pushbutton?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Paulo Silva
am 31 Aug. 2011
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 Kommentare
Paulo Silva
am 31 Aug. 2011
wordsarray is actually a cell not one array, do this:
wordscell = textscan (words, '%s');
nwords=cellfun(@numel,wordscell);
disp (nwords)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!