フォルダ内の同じ数字を持つcsvファイルの結合
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
フォルダ内に同じ数字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 commentaires
Réponse acceptée
Atsushi Ueno
le 26 Juil 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur ワークスペース変数と MAT ファイル dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!