Running of mathlab files in different subfolder automatically

2 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2018-5-6
编辑:Stephen23 2018-5-6
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.

请先登录,再进行评论。

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by