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

조회 수: 3 (최근 30일)
K E
K E 2014년 2월 17일
편집: K E 2014년 2월 17일
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
Andreas Goser
Andreas Goser 2014년 2월 17일
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 2014년 2월 17일
편집: K E 2014년 2월 17일
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.)

댓글을 달려면 로그인하십시오.

채택된 답변

Iain
Iain 2014년 2월 17일
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
K E
K E 2014년 2월 17일
편집: K E 2014년 2월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by