Main Content

writeTextDocument

テキスト ファイルへの文書の書き込み

説明

writeTextDocument(documents,filename) は、documents を指定されたテキスト ファイルに書き込みます。関数は、UTF-8 の各単語の間にスペースを入れて、1 行に 1 つの文書を書き込みます。

writeTextDocument(documents,filename,'Append',true) は、上書きする代わりにファイルに追加します。

すべて折りたたむ

文書の配列をテキスト ファイルに書き込みます。

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)

文書を一度に 1 つずつ追加して、文書の配列をテキスト ファイルに書き込みます。

トークン化された文書の配列を作成します。

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(1),filename)

extractFileText を使用してファイルのコンテンツを表示します。

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

2 番目の文書をテキスト ファイルに追加します。

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

extractFileText を使用してファイルのコンテンツを表示します。

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

入力引数

すべて折りたたむ

入力文書。tokenizedDocument 配列として指定します。

ファイルの名前。string スカラー、文字ベクトル、または文字ベクトルを含む 1 行 1 列の cell 配列として指定します。

データ型: string | char | cell

バージョン履歴

R2017b で導入