File Exchange

image thumbnail

save_to_base.m

version 1.2 (1.51 KB) by

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

4.85714
7 Ratings

1 Download

Updated

View License

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.

Comments and Ratings (10)

Bert

Bert (view profile)

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.

liu yuan

Do the job

Carlos

Carlos (view profile)

Thomas

Thomas (view profile)

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

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

Benjamin

Jeff Miller

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

1.2

Added patch to exclude 'ans' variable.

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.

MATLAB Release
MATLAB 7.8 (R2009a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video