How to count length of array?
Show older comments
hi all, im using GUIDE to form my gui.
function pushbutton1_Callback(hObject, eventdata, handles)
words = get(handles.editbox, 'string');
wordsarray = textscan (words, '%s'); %this splits up the string into an array
max_words = length(wordsarray) %this is supposed to count the number of words in the array
disp (max_words)
now, no matter how many words are keyed into the editbox, the only value returned is 1, when it should actually output the number of words in the input string. i know textscan splits the string into an array of words and i suspect that its only counting one dimension (only the row or only the column, because it stores it in a 1xK array, where k is the number of words, i think). how do i make disp() display the other dimension? or is there another function to output K from a 1xK array?
Accepted Answer
More Answers (1)
Rick Rosson
on 31 Aug 2011
Hi Jan,
Please try the following:
max_words = length(wordsarray{1});
HTH.
Rick
1 Comment
Jan Donyada
on 31 Aug 2011
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!