フォルダ内の同じ数字を持つcsvファイルの結合
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
フォルダ内に同じ数字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 Kommentare
Akzeptierte Antwort
Atsushi Ueno
am 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu ワークスペース変数と MAT ファイル finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!