Batch processing using loops
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tyee
el 12 de Mzo. de 2014
Editada: Salaheddin Hosseinzadeh
el 12 de Mzo. de 2014
I'm trying to analyze multiple .mat files that only differ in the name of each file. I essentially want to run each file under the same code, but I don't want to laboriously change the name of the loaded file. Is there syntax that I could put in the front and end of my code so I can loop the script to run for all the files in a given directory. The .mat files only differ by a sequence of numbers within the name, so could I input some sort of string beforehand, so all matlab has to do is open files based on a prewritten string. I don't know if that made sense, I'm new to this program....Thanks for your patience.
This is an example of what I'm trying to do: The data vector are the numbers that vary from file to file. All I want to do is take these numbers, put them into a file name and load that file. Is this possible?
data = [110535, 112212, 113327, 114252, 115310, 120216, 121047, 121837, 123235, 124703, 125857, 131222,132322, 133328, 134052, 135138, 140132, 141120, 142016, 143316, 144304, 145623];
for k = data(1,i) kalmanized_data = sprintf('DATA20140218_%d.kalmanized.h5-short-only.mat', k); load (kalmanized_data); CODE end
Any help is appreciated!
Thank you!
0 comentarios
Respuesta aceptada
Salaheddin Hosseinzadeh
el 12 de Mzo. de 2014
Editada: Salaheddin Hosseinzadeh
el 12 de Mzo. de 2014
Tyee this is absolutely possible. I actually did this before, but the files I want to load had some sort of familiar names and the had a different number at the end of the file name which showed the error probability of the file, so it was much easier for me to load them all using a simple loop. If your files have no such order or criteria in their names then you have to make a vector in your case 'data' and then do the rest automatically.
for x=1:14
Burst=ones(1,5);
Burst(3)=0.004+(x-1)*.001;
a=load(['D:\DVB-T- BurstChan Test\SEQ\Err_Seq',num2str(Burst(3)),'.mat'])
This is a part of that code, Name of my files where used to be 'Err_Seq_0.004.mat','Err_Seq_0.005.mat','Err_Seq_0.006.mat' and so on. This was how I used to load every single file. You don't need to use sprintf and make it so complicated! I'm sure the path for the files are the same, so you can make a string simply by concatenating strings together and when ever you have a digit or number, use num2str() and simply concatenate it with the rest of the string just as I did in the above example. Good Luck!
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!