Can I run the same script (and subfunctions) from two diffent matlab windows?
显示 更早的评论
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.
Thanks!
回答(1 个)
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.
2 个评论
Walter Roberson
2015-12-4
Also if the function overwrites the .m files themselves then you will have problems.
Matt Cooper
2022-10-7
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!