datastoreを途中から読み込む方法
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
shingo maruyama
el 12 de Mzo. de 2024
Comentada: shingo maruyama
el 18 de Mzo. de 2024
複数のcsvファイルからdatastoreを作成したとき、途中から読み込む方法はありますか?
read関数の説明では、resetして始めから読み込む方法しか書かれてなく時間がかかります。
画像ファイルの時のreadimage関数のように何番目を指定して読む方法はないでしょうか。
いい方法がありましたら教えていただけると幸いです。
2 comentarios
Kojiro Saito
el 14 de Mzo. de 2024
データストアのReadSizeによって手順が異なりますが、現在はfile (ファイル単位)になっているか20000とかの数値になっているかどちらでしょうか?前者のファイル単位での読み取りで良ければストレートなやり方があり、後者だとちょっと工夫が必要です。
Respuesta aceptada
Kojiro Saito
el 15 de Mzo. de 2024
CSV で使われる表形式データストア(tabularTextDatastore)がサポートしているpartitionで指定した位置のデータを抽出できます。ただ、位置(下記コードの変数index)は1つしか指定できないのでx番目以降をまとめて取得したい場合はindexの値を変えて繰り返し実施する必要があります。
ttds = tabularTextDatastore("*.csv");
% 分割数を取得
n = numpartitions(ttds);
% データストアを分割して4番目を取得
index = 4;
subds = partition(ttds, n, index);
% 当該データを読み込む
while hasdata(subds)
data = read(subds);
end
また、datastoreのサブセットを作れるsubsetコマンドがあるのでこれが使えるmatlab.io.datastore.FileSetのタイプでデータストアを作成することでも実現可能です。subsetでは指定する位置を複数入れられるので、3番目以降とするときは3:maxpartitions(fs)のように指定できます。
fs = matlab.io.datastore.FileSet("*.csv");
% 分割数を取得
n = maxpartitions(fs);
% 3番目以降の分割を取得
subds = subset(fs, 3:n);
while hasNextFile(subds)
% ファイル情報を取得
file = nextfile(subds);
% テーブルとして読み取り
t = readtable(file.Filename);
% 何かしらの処理
end
Más respuestas (0)
Ver también
Categorías
Más información sobre データ ストア en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!