Clean up context of anonymous function handles - bug #328733

This submission provides a workaround for MATLAB bug #328733.
421 download
Aggiornato 1 lug 2009

Visualizza la licenza

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
Creato con R2009a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Startup and Shutdown in Help Center e MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.1.0.0

Fix: correctly handle non-anonymous function handles.

1.0.0.0