user195257
user195257

Reputation: 3316

Read from txt file in Matlab

I'm having problems reading in from a txt file in matlab. The txt file is an online review, so the delimeter I want to use is just a single whitespace. I've tried using dlmread, textscan and textread but can't seem to get it to work. I want each word in the txt file to be in a seperate cell in an array. How do I go about this?

Thanks

EDIT, this is the txt file

My husband and I satayed for two nights at the Hilton Chicago,and enjoyed every minute of it! The bedrooms are immaculate,and the linnens are very soft. We also appreciated the free wifi,as we could stay in touch with friends while staying in Chicago. The bathroom was quite spacious,and I loved the smell of the shampoo they provided-not like most hotel shampoos. Their service was amazing,and we absolutely loved the beautiful indoor pool. I would recommend staying here to anyone.

Upvotes: 0

Views: 3700

Answers (2)

Smash
Smash

Reputation: 3802

If all else fails (other answers already seem good, but you specifically said the functions they proposed do not work), try something like this:

fid = fopen('test.txt');
for i = 1:1000
    A{i} = fscanf(fid,'%s',1);
end
fclose(fid)

Just make sure your loop is long enough to read every word.

Upvotes: 0

Clement J.
Clement J.

Reputation: 3032

textread('your_filename', '%s') should work.

Upvotes: 4

Related Questions