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

3 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?
  2 Comments
Andreas Goser
Andreas Goser on 17 Feb 2014
This is technically interesting and I also have a "believe", but I am hesitant to answer because I would not rely on this behaviour continues to be the same for the future. So if this is just curiosity - why don't you try? If it is for a serious application - I am sure there is a better way and wonder which problem you want to solve with this approach?
K E
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
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
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)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!