Code covered by the BSD License  

Highlights from
save_to_base.m

4.85714
4.9 | 7 ratings Rate this file 23 Downloads (last 30 days) File Size: 1.51 KB File ID: #24121 Version: 1.2

save_to_base.m

by

 

14 May 2009 (Updated )

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

| 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)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
26 Feb 2014 Bert

Bert (view profile)

 
26 Feb 2014 Bert

Bert (view profile)

Thank you very, very much. I use this in combination with xlsread1 and xlswrite2, which require Excel to be in de workspace.

Comment only
09 Oct 2013 liu yuan  
15 May 2013 Alexandre Willame

Do the job

24 Sep 2012 Carlos

Carlos (view profile)

 
25 Apr 2012 Thomas

Thomas (view profile)

Thank you for the nice function :)
A small bugfix: instead of "length(nargin)" it has to be just "nargin"

Comment only
12 Jan 2012 Arsalan

For me it does not work. I have a function that has some variables to save in workspace. I use evali('base',VarName) but that does not work. Just after file execution, all variables disappear from workspace

Comment only
02 Aug 2011 Benjamin  
20 May 2011 Jeff Miller  
16 Aug 2009 Donald

Donald (view profile)

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.

Updates
02 Jun 2009 1.1

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 1.2

Added patch to exclude 'ans' variable.

Contact us