in reply to a question about making a word frequency matrix

I know this is not a working solution to your query but is a one-liner that I have used often to get this type of information quickly for any block of text I am dealing with:
perl -nle '$c{$_}++ for split/\s/;}print map {"$_:$c{$_}\n"} sort{$c{$ +b}<=>$c{$a}}keys %c;{' file_of_WHATEVER_to_count.txt
example, to count the number of instances of each word in a file you could use split/\W/ in the place of split/WHATEVER/ or just split if you wanted to keep punctuation,etc. intact. output is ordered by most frequent occurrences (at the top of the "item:count\n" listing)