Can I run the same script (and subfunctions) from two diffent matlab windows?

25 views (last 30 days)
I have a script that calls subfunctions. I am wondering if I'll run into any problems when I call the script and hence the subfunctions from two different matlabs. The background is that I am running an optimization. I want to optimize two different sets of data independently meaning calling the optimization script from to different matlabs. Will I have problems when the script calls the subfunction which is executing the simulation? For example that input/output parameters will get messed up this way among the different matlabs. Or is matlab using some temporary versions of all called scripts and functions per workspace/matlab window?
I'd really appreciate any answers/hints/help on this.

Answers (1)

Guillaume on 4 Dec 2015
Edited: Guillaume on 4 Dec 2015
Scripts and functions are simply text files. They are not executables. So, yes They can be run without any issue(*) from as many matlab sessions as you want. Each matlab session will read the script/functions, and execute them in their own workspace.
*: unless of course, your script writes data to a fixed file, in which case both instances would overwrite each other data.
Matt Cooper
Matt Cooper on 7 Oct 2022
As of R2021b (possibly R2021a), if the calling script is edited in the second instance, the first instance will recognize those changes and apply them while the script is still running in the first instance (in my experience). In other words, the parallel execution hack of opening multiple instances and running the same script over different sets of inputs is more complicated now (you can still do it if you save multiple copies of the calling script). Better to learn how to use the parallel pool (and background pool) functionality.

Sign in to comment.


Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by