MATLAB Answers


Spell check with txt file

Asked by Kim
on 23 Feb 2013
For each word in the email, check whether the word is in the dictionary. 
Print out misspelled words.

How can you check whether the word in "sentence.txt" is in "text.txt"?

Also how can you print words not in text.txt file?



For example:

There is no one in th hous.

(It should check this sentence to "text.txt" and print out th & hous because it is not in "sentence.txt" file.)

  1 Comment

What have you tried so far?


No products are associated with this question.

1 Answer

Answer by Lalit Patil on 23 Feb 2013

 CStr = textread('sentence.txt', '%s', 'delimiter', '\n')
 CStr1 = textread('text.txt', '%s', 'delimiter', '\n')
 contained = ismember(CStr, CStr1)  % if ans 1 then it is in text.txt
 notIndata2 = CStr(~contained)     % print those are not in text.txt 
 notIndata2 = CStr(contained)      % print those are in text.txt   


Yes. In an application such as you describe, I can see a use for all of those except str2num (but not all of what you list might be needed in any one implementation.)

If your question is not a homework project, which I hope it is not, then 'textread' is part of base-MATLAB and you should use it. Why go for the elementary functions?

on 23 Feb 2013

it is a homework project, and it recommends to use those functions but I don't know how to :(

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!