How to get corresponding file in another folder?

1 回表示 (過去 30 日間)
Mr. 206
Mr. 206 2018 年 12 月 6 日
コメント済み: Mr. 206 2018 年 12 月 10 日
In one of my folders there are files like "IGN_A.txt", "IGN_B.txt", "IGN_C.txt".........
In another folder there are corresponding files like "sim_IGN_A.txt", "sim_IGN_B.txt", "sim_IGN_C.txt".............
Each of this file contains two columns of same size. How can I create a matrix where two column data from "IGN_A.txt" and two column data from "sim_IGN_A.txt" will be stored side by side. Same thing will be applied to other files.

採用された回答

Cris LaPierre
Cris LaPierre 2018 年 12 月 7 日
You can include path information in your load command. If you know the path, use that along with the filename to open both files. From there, just load the data from both files, and then create the two matrices combining the data as you wish.
Look into fullfile to help you assemple the full path and filename.
  3 件のコメント
Cris LaPierre
Cris LaPierre 2018 年 12 月 7 日
編集済み: Cris LaPierre 2018 年 12 月 7 日
Allfiles_Exp will be all files in that folder that match the filter '*ign*.txt'.
Allfiles_Exp_Sim will be all files in that folder that match the filter '*sim_ign*.txt'. There is no connection between the files loaded in either location.
It sounds like instead, Allfiles_Exp_Sim should be the filenames in Allfiles_Exp prepended with 'sim_'. If your naming convention is strictly adhered to, then there is no need to use dir on the Sim folder. Instead, use fullfile with the path to the Sim folder plus the names you get from the Exp folder prepended with 'sim_' to load each file pair.
BTW, the second for loop in your code loads every Sim file for a single Exp file. It is unnecessary with this new approach and can be removed.
Flame_speed__Exp_folder = './ali/LFS/test/Test_rig';
Flame_speed__Sim_folder = './ali/PostProcess';
% To get all the files in that directory and with desired file name pattern.
Allfiles_Exp = dir(fullfile(Flame_speed__Exp_folder, '*ign*.txt'));
for k = 1:length(Allfiles_Exp)
fullFileName = fullfile(Allfiles_Exp(k).folder, Allfiles_Exp(k).name));
READ=dlmread(fullFileName,'',1,0,"emptyvalue",911911911);
fullFileName_Sim = fullfile(Flame_speed__Sim_folder, strcat('sim_',Allfiles_Exp(k).name);
READ=dlmread(fullFileName_Sim,'',1,0,"emptyvalue",911911911);
...
end
Incidentally, your inputs for dlmread are giving me an error. If it is working for you, then disregard. However, the 'emptyvalue' argument is not an option per the documentation.
Mr. 206
Mr. 206 2018 年 12 月 10 日
Thank you so much.
I was doing so because in future there can be files like "sim_IGN_A_Mech01.txt", "sim_IGN_A_Mech02.txt", "sim_IGN_A_Mech03.txt"........... which all correspond to same "IGN_A.txt" file.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by