Running of mathlab files in different subfolder automatically

2 vues (au cours des 30 derniers jours)
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 commentaire
Stephen23
Stephen23 le 6 Mai 2018
Modifié(e) : Stephen23 le 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.

Connectez-vous pour commenter.

Réponse acceptée

Hypolite Richardson
Hypolite Richardson le 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

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by