Effacer les filtres
Effacer les filtres

datastoreによりデータの読み込み

1 vue (au cours des 30 derniers jours)
Naoki Ishibashi
Naoki Ishibashi le 29 Oct 2016
Commenté : Naoki Ishibashi le 29 Oct 2016
以下のコードで365個テキストファイルを読み込もうとしたら以下のエラーが出てしまいました、プロパティーを変更しなくてはいけないと考えているのですがうまくいかず何かアドバイス頂けると幸いです。 テキストファイルは添付のものと形式(区切り位置など)、データ数全て同じものがTA20040101.txt~TA20041231.txtです。
dsX = datastore ('TA2004*.txt');
dsX.MultipleDelimitersAsOne = true;
dsX.NumHeaderLines = 0;
x = readall(dsX);
y = reshape(x.Var1,10368,[]);
以下エラー
Error using datastore (line 165)
Cannot detect TextscanFormats from file: 'C:\Users\Naoki Ishibashi\Documents\MATLAB\HW3\TA2004\TA20040101.txt'. Specify TextscanFormats when you create the datastore. Verify the Text
Format and Advanced Text Format Properties.
Error in test (line 1)
dsX = datastore ('TA2004*.txt');
  2 commentaires
Kojiro Saito
Kojiro Saito le 29 Oct 2016
テキストファイルの添付が無いようなので、お手数ですがもう一度添付していただけますか? おそらくデータの区切りの指定などが必要なのですが、実際にデータを見たほうが早いですので。
Naoki Ishibashi
Naoki Ishibashi le 29 Oct 2016
大変失礼致しました テキストデータ添付させて頂きます

Connectez-vous pour commenter.

Réponse acceptée

michio
michio le 29 Oct 2016
添付頂いた text ファイルは値がスペースで区切られ横一列に並んだデータの様です。 RowDelimiter オプションで「スペースで行を区切る」と認識させることで、すべてのデータを縦一列の形で読み取ることが出来ます。
dsX = datastore ('TA2004*.txt', 'ReadVariableNames', false, 'RowDelimiter', ' ');
x = readall(dsX);
y = reshape(x.Var1,10368,[]);
  2 commentaires
michio
michio le 29 Oct 2016
参考情報:
datastore のオプションの中でも経験上、下記の5つは要注目です。
  • NumHeaderLines — ファイルの先頭でスキップする行数
  • Delimiter — フィールドの区切り記号
  • RowDelimiter — 行区切り記号文字
  • Whitespace — 空白文字
  • MultipleDelimitersAsOne — 複数の区切り記号の取り扱い
オプションも多く、それぞれ一つづつ確認するのは最初は大変かと思いますが、一度慣れるとその他様々な形式のファイルに柔軟に対応できますので、是非一度挙動を確認してみてください。各オプション設定は
の2ページに例題も合わせて情報がありますので参考にしてください。
Naoki Ishibashi
Naoki Ishibashi le 29 Oct 2016
できました、ご丁寧にご回答頂きありがとうございます。

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by