how to count words in a cell array
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I have a cell array that i want to count the words in the strings inside the cell array
this is what i have so far. I need a general direction on where to go from here. 
function [words] = howManyWords(ca)
i = 1
ca = {{'Let it go'} {'Let it go'} { 'Can''t hold it back anymore'}}
stringbaby = string(ca)
howmanystrings = length(stringbaby)
for i = 1:howmanystrings
    n = strfind(ca(i),' ')
    words(i) = length(n) + 1
    i = i + 1
end
end
1 comentario
  Matt J
      
      
 el 26 de Oct. de 2022
				I need a general direction on where to go from here
Why do you need to go anywhere?
Respuestas (2)
  David Hill
      
      
 el 26 de Oct. de 2022
        ca = {{'Let it go'} {'Let it go'} { 'Can''t hold it back anymore'}}
for i = 1:length(ca)
   a=ca{i};
   a=strsplit(a{1},' ');
   words(i)=length(a)';
end
words
0 comentarios
  Matt J
      
      
 el 26 de Oct. de 2022
        ca = {{'Let it go'} {'Let it go'} { 'Can''t hold it back anymore'}};
NumWords = cellfun(@(c)sum(c{1}==' ')+1,ca)
0 comentarios
Ver también
Categorías
				Más información sobre Structures 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!


