How to obtain data from editbox using a pushbutton?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Paulo Silva
el 31 de Ag. de 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 comentarios
Paulo Silva
el 31 de Ag. de 2011
wordsarray is actually a cell not one array, do this:
wordscell = textscan (words, '%s');
nwords=cellfun(@numel,wordscell);
disp (nwords)
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!