Count word frequency, please help
Mostrar comentarios más antiguos
I have a column which contain cells each contain a text, and i want to count the frequency of each word
I write this code - which works - to count the word frequency and sort it
str = alldata{:,51};
C = regexp((str),' ','split')';
[val,idxC, idxV] = unique(C);
n = accumarray(idxV,1);
m = [n idxC] ; %n occurences for word C(idxC)
y = [val num2cell(n)]; % t without sort
[~, so]= sort(n,'descend'); % sort the frequencies descend and rest alphabet
words= val(so); % sort words by frequency
freq= n(so); % sort frequency
z = [words num2cell(freq)]; % show words with frequency sort
it give me a good answer which:

this work on the first cell only, but i want to make the word frequency to the whole cells

I try this:
j=1;
for i=1:size(alldata,1)
fid(j,1) = alldata(i,51);
C(k,1) = regexp((fid(j,1)),' ','split')';
[val{k},idxC{k}, idxV{k}] = unique(C{k});
n{k} = accumarray(idxV(k),1);
j=j+1;
end
m = [n idxC] ;
y = [val num2cell(n)];
[~, so] = sort(n,'descend');% s= sort(n);
words = val(so);
freq = n(so);
z = [words num2cell(freq)];
but it didn't work , it seems i have to merge all cells first.
- | how i can get the word frequency of the whole file ? | *
3 comentarios
Amr Hashem
el 22 de Jul. de 2015
Cedric
el 23 de Jul. de 2015
I return the question to you ;-)
Alex
el 11 de Nov. de 2018
How to implement the same using MapReduce? Each row of one column will be sent to different mapper?
Respuesta aceptada
Más respuestas (1)
Amr Hashem
el 24 de Jul. de 2015
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!