If your text data is contained in multiple files in a folder, then you can import the text data into MATLAB using a file datastore.
Create a file datastore for the example sonnet text files. The examples sonnets have file names "exampleSonnetN.txt", where N is the number of the sonnet. Specify the read function to be extractFileText.
bag — Input bag-of-words or bag-of-n-grams model bagOfWords object | bagOfNgrams object
Input bag-of-words or bag-of-n-grams model, specified as a bagOfWords object or a bagOfNgrams object.
documents — Input documents tokenizedDocument array | string array of words | cell array of character vectors
Input documents, specified as a tokenizedDocument array, a string array of words, or a cell array of
character vectors. If documents is not a
tokenizedDocument array, then it must be a row vector representing
a single document, where each element is a word. To specify multiple documents, use a
tokenizedDocument array.