Read from txt file

40 次查看(过去 30 天)
Kim
Kim 2013-2-23
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);

采纳的回答

Lalit Patil
Lalit Patil 2013-2-23
% 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 个评论
Kim
Kim 2013-2-23
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.
Lalit Patil
Lalit Patil 2013-2-23
CStr = textread('words.txt', '%s', 'delimiter', '\n')
Try this only single line..

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2013-2-23
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 个评论
Kim
Kim 2013-2-23
it is still showing the same thing.
Image Analyst
Image Analyst 2013-2-23
You've accepted an answer, so I guess it's solved now, and I don't need to answer.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by