I am looking for a workaround for the following problem:
- Create a script
foo.m
containingfun = @(x)(x*x)
- Run
foo
. This creates the variablefun
. - Delete
foo.m
- Try running
fun(2)
.
In recent versions of MATLAB (I am using R2019b) this results in an error:
Previously accessible file "foo.m" is now inaccessible.
Somehow, the anonymous function is tied to the file in which it was defined.
Is it possible to somehow "detach" it so that it would continue working even after the file was deleted?
For those curious why I need this, it is for fixing MATLink, the Mathematica/MATLAB interface, for recent versions of MATLAB.
fun
. It doesn't work iffoo.m
was deleted, even though MATLAB knows about thefun
variable, and can even show me the definition. – Szabolcsfun
as a global variable,both in the command line and in the script, work? – rahnema1global
keyword to declare variables. – rahnema1