MATLAB Answers

Kim
0

Read from txt file

Asked by Kim
on 23 Feb 2013

I have to 1) Read in a dictionary of common English words from words.txt.

and

2) Read in an email with misspellings from email.txt

in one file

I just started learning matlab and I am a beginner. I did this, but it doesn't work. Help please.

==

==

fip = fopen('words.txt', 'r');

Data = fread(fid);

CharData = char(Data);

fclose(fid);

disp(Data);

fip = fopen('email.txt', 'r');

Data = fread(fid);

CharData = char(Data);

fclose(fid);

disp(Data);

  0 Comments

Tags

Products

No products are associated with this question.

2 Answers

Answer by Lalit Patil on 23 Feb 2013
 Accepted answer

% Try this

 fid = fopen('words.txt', 'r'); 
 Data = fread(fid);
 CharData = char(Data);
 fclose(fid);
 disp(Data);
 fid = fopen('email.txt', 'r');
 Data = fread(fid);
 CharData = char(Data);
 fclose(fid);
 disp(Data);

If not works than what is the error..? Show it..

  2 Comments

Kim
on 23 Feb 2013

The words.txt has words

be

the

as

if

etc...

but when I run it, it shows numbers

100

110

99

10

etc..

I need to show the words that are in 'word.txt' as result instead of those number.

 CStr = textread('words.txt', '%s', 'delimiter', '\n')

Try this only single line..


Answer by Image Analyst
on 23 Feb 2013

What doesn't work? You read in two files, and that's what you were supposed to do. So what doesn't work? Please copy and paste your error message or whatever else tells you that it is not working.

  4 Comments

Use fgetl() instead of fread().

Kim
on 23 Feb 2013

it is still showing the same thing.

You've accepted an answer, so I guess it's solved now, and I don't need to answer.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!