Running of mathlab files in different subfolder automatically

2 Ansichten (letzte 30 Tage)
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 Kommentar
Stephen23
Stephen23 am 6 Mai 2018
Bearbeitet: Stephen23 am 6 Mai 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Hypolite Richardson
Hypolite Richardson am 6 Mai 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

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by