0

The problem is there are some group like auto,business etc and some words in these groups like car,gun etc in a txt file,'text.txt'

sub.autos $tab$ shift clutch car gear clutch car turn advanc repli
sub.autos $tab$ bike long clutch pulsar
talk.politics.gun $tab$ assault AK-47 war assault
talk.politics.gun $tab$ country war terror

and I need to create TF-IDF ( term frequency – inverse document frequency), that is, number of times a word occurs in a particular group in a form of a matrix in which each row will correspond to a group, and each column represents the occurrence of a particular word in respective group.

I know the method for txt file to 1-d array using textread but change it in 2-d made me clueless.i am a beginner in matlab and any help would be appreciated.

PS - tf-idf wiki link http://en.wikipedia.org/wiki/Tf-idf

user2771151
  • 411
  • 1
  • 7
  • 18
  • 1
    Hi, read the documentation of `textscan()`, `unique()`, and `histc()` and come back with some code examples of what you tried. – McMa Feb 19 '14 at 07:57

1 Answers1

0

Try reading the section on using parameters with textread(). One of the parameters is 'whitesapce' that can be set to '/n'.

For example given the following data.txt file

Sally Level1
12.34 45 Yes

Using the code

[names, types] = textread('data.txt', '%s %s', 1, 'whitespace', '\n')

Returns

names = 'Sally Level1'
types = '12.34 45 YES'

I am no expert with using textread, but I hope this gives you something you can use.

NickF
  • 83
  • 8