Saving workspace from a class
2 views (last 30 days)
Show older comments
Vivien SCHMITT
on 7 Dec 2015
Edited: Walter Roberson
on 8 Dec 2015
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
Accepted Answer
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
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) )
More Answers (0)
See Also
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!