Clean up context of anonymous function handles - bug #328733
MATLAB saves some anonymous function handles with too much context information - see MATLAB bug #328733. In some cases, this will crash MATLAB when loading the function handle (e.g. if some large variables or objects that do not support serialisation are saved).
This function provides a workaround - it recreates the function handle without unnecessary context information.
Currently, there is one limitation: bound variables are not included correctly. E.g.
x = 1;
f = @(y)mod(y,x);
f1 = clean_funhandle(f);
f(2)
ans = 0
f1(2)
??? Undefined function or variable 'x'.
Error in ==> clean_funhandle>@(y)mod(y,x)
This is because x is not defined in the context of clean_funhandle.
The alternative version
f = @(y)mod(y,2);
f2 = clean_funhandle(f);
works. Here, the second argument is a constant, which is replaced correctly.
Cita come
Volkmar Glauche (2025). Clean up context of anonymous function handles - bug #328733 (https://it.mathworks.com/matlabcentral/fileexchange/24613-clean-up-context-of-anonymous-function-handles-bug-328733), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Compatibilità della piattaforma
Windows macOS LinuxCategorie
Tag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
