0

I want to check words in an array one by one against a dictionary file, what would be the simplest way of doing this?

e.g.

word = nchoosek('london' , 3)

and I want to check if each of the 3 letter words produced are in a dictionary file.

e.g.

dictionary(word)

Thanks.

user2975192
  • 317
  • 2
  • 6
  • 18

1 Answers1

0

If you have a cell-array of words you want to check, you should use ismember. So, if you had a dictionary array dict and a set of words words, you would use

check = ismember(words,dict);

where check would be something along the lines of [0,1,1], if the first word wasn't in the dictionary, but the other two were.

EDIT:

I guess that dictionary is a function? Sorry, I didn't pick up on that the first time around. In that which case, borrowing from this answer to a different question, you can do the following:

dict_fun = @(word,trash)dictionary(word);
check = bsxfun(dict_fun,nchoosek('london',3),1);
Community
  • 1
  • 1
MrAzzaman
  • 4,734
  • 12
  • 25
  • Thanks. The problem is that the dictionary is a file which only accepts one word at a time, so this wouldn't work. – user2975192 Nov 21 '13 at 01:35
  • Is it possible to load the dictionary into a cell-array? For instance, on my linux distribution I can use `fid=fopen('/usr/share/dict/words');dict = textscan(fid,'%s');fclose(fid);` to load in a dictionary of words, and I would then be able to use that in the means that I described above. – MrAzzaman Nov 21 '13 at 01:44
  • Nope, the only way to check if a word is in the dictionary is to input them one by one with the syntax dictionary('word'). So I need to create a for loop to check each word produced with nchoosek somehow? – user2975192 Nov 21 '13 at 01:47
  • Sorry, I didn't realise that `dictionary` was a function. See my amended answer. – MrAzzaman Nov 21 '13 at 02:19