I'm trying to calculate the average length of words in a sentence. I'm having trouble getting the length of a string. Here's what's happening:
>> a='string'; >> length(a)
ans =
6
That works great. But if I try it like this:
>> string='The rain in Spain.';
>>words=strsplit(string)
words =
'The' 'rain' 'in' 'Spain.'
>> words(1)
ans =
'The'
>> length(words(1))
ans =
1
It's not giving me 3, which should be the length of the first object in words.
Best Answer