This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

writeTextDocument

Write documents to text file

Syntax

writeTextDocument(documents,filename)
writeTextDocument(documents,filename,'Append',true)

Description

example

writeTextDocument(documents,filename) writes documents to the specified text file. The function writes one document per line with a space between each word in UTF-8.

example

writeTextDocument(documents,filename,'Append',true) appends to the file instead of overwriting.

Examples

collapse all

Write an array of documents to a text file.

documents = tokenizedDocument([
    "an example of a short sentence" 
    "a second short sentence"])
documents = 
  2x1 tokenizedDocument:

    6 tokens: an example of a short sentence
    4 tokens: a second short sentence

filename = "documents.txt";
writeTextDocument(documents,filename)

Write an array of documents to a text file by appending the documents one at a time.

Create an array of tokenized documents.

documents = tokenizedDocument([
    "an example of a short sentence" 
    "a second short sentence"])
documents = 
  2x1 tokenizedDocument:

    6 tokens: an example of a short sentence
    4 tokens: a second short sentence

Write the first document to the file.

filename = "documents.txt";
writeTextDocument(documents(1),filename)

View the contents of the file using extractFileText.

str = extractFileText(filename)
str = 
"an example of a short sentence"

Append the second document to the text file.

writeTextDocument(documents(2),filename,'Append',true)

View the contents of the file using extractFileText.

str = extractFileText(filename)
str = 
    "an example of a short sentence
     a second short sentence"

Input Arguments

collapse all

Input documents, specified as a tokenizedDocument array.

Name of the file, specified as a string scalar or character vector.

Data Types: string | char

Introduced in R2017b