detach - clear variable while passing to a function

func_name( detach(variable) ) Remove variable from the workspace before passing to the func_name()
107 Downloads
Updated 17 Dec 2011

View License

In matlab, when a variable passed into a function is modified within the function, a copy of the variable is created on the fly, unless the variable is completely a temporary variable or unless the same variable is retrieved as an output argument.

detach() is a very simple function to clear the variable from the caller workspace and convert it into a temporary variable that is not accessible anymore upon return from the function call. If variable doesn't exist in another workspace, this avoids copy-on-write. detach() can also be handy for code clarity.

Cite As

Gokberk Cinbis (2025). detach - clear variable while passing to a function (https://se.mathworks.com/matlabcentral/fileexchange/34246-detach-clear-variable-while-passing-to-a-function), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0