Running of mathlab files in different subfolder automatically

2 visualizaciones (últimos 30 días)
Hi, I am writing a piece of code which opens subfolders ( Simulation_1 to Simulations_10 ) and runs a file named: ( A_File_to_run_programs.m) automatically.
The problem: the current folder stays in the parent directory and not in the folder Simulation_1 to Simulation_10
Thanks for your help in advance.
Hypolite
  1 comentario
Stephen23
Stephen23 el 6 de Mayo de 2018
Editada: Stephen23 el 6 de Mayo de 2018
What you are trying to do is slow and complex: copying files in order to run them is not required, because all MATLAB functions that accept filenames will accept absolute/relative filenames, so all you need to do is add the file path to the name, before passing it to whatever function needs to use it.
Do NOT:
  • Use slow cd
  • Copy code/mfiles into data folders just so that they can be run on some data.
Instead simply write your code so that you correctly pass the directory path with the filenames, and your code will be simpler, more efficient, and easier to debug.
DO:
  • Keep your code is one place, separate from your data.
  • Use absolute/relative filenames.

Iniciar sesión para comentar.

Respuesta aceptada

Hypolite Richardson
Hypolite Richardson el 6 de Mayo de 2018
Hi Stephan,
I am a beginner so thanks for the information, pertaining to debugging and how to really use mathlab correctly.
I will strucute my code different, so as you said will pass thru the directory path.
Thanks a million.
Hypolite

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by