Main Content


Check if word is member of documents

Since R2022b



    tf = containsWords(documents,words) returns 1 where any token of documents matches words and returns 0 otherwise.

    tf = containsWords(documents,words,IgnoreCase=flag) also specifies whether to ignore letter case when checking words.


    collapse all

    Create an array of tokenized documents.

    documents = tokenizedDocument([
        "an example of a short sentence" 
        "a second short sentence"]);

    Check for documents containing the word "second".

    tf = containsWords(documents,"second")
    tf = 2x1 logical array

    Input Arguments

    collapse all

    Input documents, specified as a tokenizedDocument array.

    Words to check, specified as one of these values:

    • String array

    • Character vector

    • Cell array of character vectors

    • pattern array

    If words contains multiple words, then the function returns 1 where any of the words appear in the corresponding document.

    Option to ignore case, specified as one of the these values:

    • 0 (false) – Treat candidate matches that differ only by letter case as nonmatching.

    • 1 (true) – Treat candidate matches that differ only by letter case as matching.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

    Version History

    Introduced in R2022b