規則性のある複数のファイルで同一の計算の仕方
Show older comments
まず,a01.csv,a02.csv,a03.csv…のような名前に規則性のある複数ファイルがあります。
例えば,それぞれのファイルの1列目と2列目のデータを一様に掛け算をしたいのですが,いい方法はありますでしょうか?
よろしくお願いします。
Accepted Answer
More Answers (1)
Atsushi Ueno
on 28 Sep 2023
データストアを使う方法
for i = 1:10
writematrix(randi(9,5,2), sprintf('a%02d.csv',i))
end % 動作確認用サンプルCSVファイルa01.csv,a02.csv,a03.csv…を10個作成
ttds = tabularTextDatastore(pwd); % 上記ファイルをデータストアに登録
tds = transform(ttds, @myProcessFunction); % 変換(1列*2列⇒3列)
writeall(tds,pwd,'OutputFormat','csv','FilenameSuffix','mod'); % データストアをファイルに書き出す
% ls * % 結果確認用 カレントフォルダ直下にフォルダが作成され、内部に新たなCSVファイル群が出力される
% a = dir; cd (a(end).name); type a01mod.csv % 結果確認用
function x = myProcessFunction(x)
x.Var3 = x.Var1 .* x.Var2; % 変換(1列*2列⇒3列)
end
Categories
Find more on ワークスペース変数と MAT ファイル in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!