How to get corresponding file in another folder?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mr. 206
am 6 Dez. 2018
Kommentiert: Mr. 206
am 10 Dez. 2018
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.
0 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 7 Dez. 2018
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.
3 Kommentare
Cris LaPierre
am 7 Dez. 2018
Bearbeitet: Cris LaPierre
am 7 Dez. 2018
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations 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!