find list of distict 5 letter english words in matlab

To find a list of distinct 5-letter English words in MATLAB, you can follow these steps:

  1. Download a dictionary file, such as this one: https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/35316/versions/5/previews/wordlist.mat/index.html. Place it in your working directory.

  2. Load the dictionary file into MATLAB using the load() function:

main.m
load('wordlist.mat');
22 chars
2 lines
  1. Convert the dictionary variable into a cell array using the struct2cell() function:
main.m
wordCell = struct2cell(wordlist);
34 chars
2 lines
  1. Filter the cell array to keep only 5-letter words using the cellfun() function and the length() function:
main.m
fiveLetterWords = wordCell(cellfun('length',wordCell)==5);
59 chars
2 lines
  1. Use the unique() function to find the distinct words in the cell array:
main.m
distinctWords = unique(fiveLetterWords);
41 chars
2 lines

The distinctWords variable now contains a list of the distinct 5-letter English words in the dictionary.

gistlibby LogSnag