Saving workspace from a class

2 views (last 30 days)
I'm looking to save the workspace from a method of a class. Using just 'save(filename)' it saves only the object. Is there a way to save the entiere workspace from a class?
classdef DataFile
properties
filename
end
methods
function self=DataFile(filename) % creator
self.filename=filename;
end
function save(self) %save the current workspace
save([self.filename, '.mat']);
end
end
end
  1 Comment
Vivien SCHMITT
Vivien SCHMITT on 7 Dec 2015
And so how can we save the overall workspace? any property to define in the save call?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Dec 2015
It is saving the entire workspace. You are inside a function, and each function has its own workspace. The only thing in that workspace is what has been passed in, which here you name self.
There may be items in an enclosing workspace, but save() without named variables is defined as working with the current workspace.
  2 Comments
Walter Roberson
Walter Roberson on 7 Dec 2015
Edited: Walter Roberson on 8 Dec 2015
What overall workspace is that? Are you referring to the workspace of the routine that invokes the save method?
evalin('caller', sprintf('save(''%s.mat'')', self.filename) )
Vivien SCHMITT
Vivien SCHMITT on 7 Dec 2015
Thanks! actually you made me discover
evalin('base', sprintf('save(''%s.mat'')', self.filename) )
Best

Sign in to comment.

More Answers (0)

Categories

Find more on Argument Definitions in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!