Run a code multiple times in different directories
Mostrar comentarios más antiguos
Dear Matlab Users
I have 100 files which ordered by name like i_1 to i_100 and in each file I have a text file which called input.txt and a run.m file
which each time I shoud go to each directory and run this run.m which give me an output.txt by doing some changes in input.txt/ and this takes so long
My question is that how can I write a code in matlab which goes to each file and run the run.m file and save my output in that directory automatically!!!!
Thanks in advance for your help
6 comentarios
darova
el 28 de Ag. de 2019
I think for loop will be cool
Sulaymon Eshkabilov
el 28 de Ag. de 2019
The link provided by Walter has complete and sweet answers to the question.
"... and a run.m file"
Is run.m a script or a function?
I suspect that the name run.m will cause you problems. You should change their names.
"I wrote this code ..."
Actually you copied one of my answers, including the comments verbatim:
salman
el 3 de Sept. de 2019
Respuestas (2)
"but it has a problem for openning and running the .m file in the folder, any idea??"
Your code opens a text file, and then closes it immediately, without writing anything to the file:
savename = "run";
f = fopen([savename '.m'],'wt');
fclose(f);
This means that run.m is totally empty (because you just discarded any content with the w option).
Then, immediately after creating a totally empty script, you run it:
run(savename);
What do you expect running an empty script should do? I would not expect it to do anything.
Categorías
Más información sobre Data Import and Analysis en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!