5.0

5.0 | 1 rating Rate this file 131 downloads (last 30 days) File Size: 1.51 KB File ID: #24121

save_to_base.m

by Phillip M. Feldman

 

14 May 2009 (Updated 18 Aug 2009)

Code covered by BSD License  

copies variables from the workspace of the calling function to the base workspace

Download Now | Watch this File

File Information
Description

save_to_base() copies variables in the workspace of the calling function to the base workspace. This makes it possible to examine a function's internal variables from the Matlab command prompt after the calling function terminates.

If the optional argument "overwrite" is present and has a non-zero value, variables in the workspace of the caller will overwrite variables in the base workspace having the same name. Otherwise, preexisting variables in the base workspace will not be overwritten.

MATLAB release MATLAB 7.8 (R2009a)
Zip File Content  
Other Files license.txt,
save_to_base.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
16 Aug 2009 Donald

I found trouble when I had a stray "ans" variable floating around. I got this message:

??? The variable "ans" is undefined.

To avoid trying to copy "ans", I modified save_to_base.m so that the for loop now reads:

for i= 1 : length(variables)
    if ~strcmp(variables{i},'ans')
        tmp= evalin('caller',variables{i});
        assignin('base',variables{i},tmp);
    end
end

Very nice little function.

Please login to add a comment or rating.
Updates
02 Jun 2009

This file replaces save_variables, and fixes two problems:

- It is no longer necessary to nest the function.
- A calling argument has been added to control whether preexisting variables in the base workspace are overwritten.

18 Aug 2009

Added patch to exclude 'ans' variable.

Tag Activity for this File
Tag Applied By Date/Time
save variables Phillip M. Feldman 15 May 2009 10:12:30
base workspace Phillip M. Feldman 15 May 2009 10:12:30
debugging Phillip M. Feldman 15 May 2009 10:12:30
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com