Great question. You may have to break it down into two different functions: one that calculates the initialization and returns its results, and the other that performs your function.
[heavyCompResults,otherHeavyResults] = initComputation(initParams);
Then:
performComputation(compParams,heavyCompResults,otherHeavyResults);
Alternatively, you can write things in a file rather than passing it through Matlab.
initComputation(initParams,initResultsFname); %writes initResultsFname
Then:
performComputation(compParams,initResultsFname); %reads initResultsFname
Another alternative:
Make your code in a DLL and use the loadLibrary function in Matlab . Thus, when you create a static file, it should probably remain in memory between calls. But I did not confirm this.
source share