Azzera filtri
Azzera filtri

How to get corresponding file in another folder?

3 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Cris LaPierre
Cris LaPierre il 7 Dic 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.
Look into fullfile to help you assemple the full path and filename.
  3 Commenti
Cris LaPierre
Cris LaPierre il 7 Dic 2018
Modificato: Cris LaPierre il 7 Dic 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.
Mr. 206
Mr. 206 il 10 Dic 2018
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by