MATLAB: Saving workspace from a class

classsave

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

Best Answer

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.