フォルダ内の同じ数字を持つcsvファイルの結合
4 views (last 30 days)
Show older comments
フォルダ内に同じ数字nが入ったA_n.csvとB_.csvがあります。
AとBの行列は一致しています。
これをAのデータの横にBのデータを追加したA+B_n.csvにまとめたいと考えています。
AとBをまとめるにはcat(2,A,B)で良いかと思うのですが、
フォルダ内に同じ数字nが入ったAとBをfor構文を使って一気にまとめる方法がわかりません。
どのようにしたら同じ数字nが入ったファイルAとBを抽出してまとめることができますでしょうか?
0 Comments
Accepted Answer
Atsushi Ueno
on 26 Jul 2022
selpath = uigetdir; % 同じ数字を持つcsvファイルの入ったフォルダを選択する
cd(selpath)
filelist = dir(fullfile(selpath,'A_*.csv'));
for n = 1:length(filelist)
A = readmatrix(filelist(n).name);
B = readmatrix(strrep(filelist(n).name,'A','B'));
A_B = cat(2,A,B); % くっ付ける
writematrix(A_B,strrep(filelist(n).name,'A','A+B'));
end
More Answers (0)
See Also
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!