detach - clear variable while passing to a function
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
Platform Compatibility
Windows macOS LinuxCategories
- Simulink > Block and Blockset Authoring > Author Block Algorithms > Author Blocks Using MATLAB > Author Blocks Using MATLAB System Objects > Customize System Objects for Simulink >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 | 
