Does evalin use additional memory when assigning the variable in the function or does it use a reference?
alpha = evalin('base','alpha');
Best Answer
At one level of abstraction, calling a function normally is equivalent to pulling out the function header and setting up the parameter list, and then using eval on the code.
eval() and evalin() are not somehow emulating code: they use the normal internal expression tokenizer, getting back a parse tree, which is submitted to the execution engine. This is not just "like" how matlab executes functions and scripts: itis how matlab executes functions and scripts.
Thus, evalin() processes the same way the line of code would be processed intthat environment (except possibly details of caching), so it would give whatever result that code would. Which is to say that copy-on-write is used, which provides references to variables.
The correct function to use is assignin, not evalin:
assignin('base','data',data)
Probably even better would be to just use the debugging tools: use a breakpoint to stop the code on a suitable line, and then look at whatever variables you want. This means you do not need to add code or change the function, and gives you access to all variables in that workspace:
Best Answer