datastoreを途中から読み込む方法
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
shingo maruyama
il 12 Mar 2024
Commentato: shingo maruyama
il 18 Mar 2024
複数のcsvファイルからdatastoreを作成したとき、途中から読み込む方法はありますか?
read関数の説明では、resetして始めから読み込む方法しか書かれてなく時間がかかります。
画像ファイルの時のreadimage関数のように何番目を指定して読む方法はないでしょうか。
いい方法がありましたら教えていただけると幸いです。
2 Commenti
Kojiro Saito
il 14 Mar 2024
データストアのReadSizeによって手順が異なりますが、現在はfile (ファイル単位)になっているか20000とかの数値になっているかどちらでしょうか?前者のファイル単位での読み取りで良ければストレートなやり方があり、後者だとちょっと工夫が必要です。
Risposta accettata
Kojiro Saito
il 15 Mar 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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su データ ストア in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!