Environment Capture

Capture the environment (or scope, maybe even call it a closure) of the function caller.
659 Downloads
Updated 25 Mar 2009

View License

function env = env_capture(varargin)
% function env = env_capture(varargin)
% Capture the scope/environment of the caller. This is useful
% to snapshot in a running function all local (and local global)
% including persistent variables with their bindings.
%
% If no arguments provided, returns all bindings from caller context.
% Example execution:
% env = env_capture('ignore', 'ans', 'maxbytes', 100);
%
% Optional Input:
% varargin = keyword/argument pair: (keyed on first letter of keyword)
% +-------+----------+------------------------------------+
% |keyword| value | description |
% | |(example) | |
% +-------+----------+------------------------------------+
% | m | 1000 | maximum number of bytes of |
% | | | varibles to capture |
% +-------+----------+------------------------------------+
% | i | 'ans' | variable name to ignore |
% +-------+----------+------------------------------------+
%
% Output:
% env = <struct> whose fieldnames are the variables declared/bound
% in the scope of the caller and whose values are the
% values of the variables.
%
% Note: multiple variables can be ignored like in the following:
% env_capture('ignore', 'ans', 'ignore', 'beta', 'maxbytes', 1000);
%
% Author: David Weinstein (dweinst@alum.rpi.edu)

Cite As

David Weinstein (2024). Environment Capture (https://www.mathworks.com/matlabcentral/fileexchange/23434-environment-capture), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

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