Can I run 2 versions of a function in 2 different Matlab sessions?

5 views (last 30 days)
I am wondering if it is possible to run 2 versions of the same function in 2 different Matlab sessions.
  • Let's say I have a function named myFunction.m, and I start a Matlab session ("Session 1") and run a script which calls myFunction many times over its 2-hour run time. Let's call this version of myFunction.m "Version 1".
  • While session 1 is running the script, I edit myFunction (call this "Version 2"). I save myFunction with the original name and in the original location.
  • I then open another Matlab session ("Session 2"), and run the script which calls myFunction many times.
I believe Session 1 will continue to run Version 1 of myFunction, while Session 2 will run Version 2 of myFunction. Is that correct?
K E on 17 Feb 2014
Edited: K E on 17 Feb 2014
Here is the problem I am trying to solve: I am running many parameter sweeps. For faster completion, I run the program on several computers. In my example above, myFunction generates the parameter combinations that will be run by the script, with output files saved locally for each parameter combination (our network is slow). On one computer, I run one set of parameter combinations; on another computer, I run another. I suppose a smarter way to do this would be to pass in the parameter combinations as inputs to the script which runs the simulations, rather than to populate the parameter combinations from a function inside the script. (I hate to admit how challenging it has been for me to manage this large batch of simulations, in terms of where to store the output, how to keep track of what parameter combinations to run, etc.)

Sign in to comment.

Accepted Answer

Iain on 17 Feb 2014
You most certainly can run Version 1 of function "blah" in one instance of matlab, update blah to version 2, open up a second instance of matlab, and run the function.
Why wouldn't you just use a different function name for version 2 though? Its less prone to things going wrong.
  1 Comment
K E on 17 Feb 2014
Edited: K E on 17 Feb 2014
I am realizing I don't need to re-use the function name; I could have two as you say, myFunction1 (version 1) and myFunction2 (version 2), which are called from the script when it is executed in session 1 and session 2 respectively. I just want to make sure that if the script in session 1 runs for a long time (more like 2 days than the 2 hours I indicated before), it never re-compiles so that it starts using Version 2. I don't want to rename the script because it is used across many more versions than I indicated, let's say 50.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!