Code covered by the BSD License  

Highlights from
nclear

from nclear by Qun HAN
Clear all the other variables from the callers workspace except the specified ones.

nclear(varargin)
function nclear(varargin)
%NCLEAR Clear all the other variables from the caller's workspace except the specified ones.
% NCLEAR(VAR1,VAR2,....) clears all the other variables except VAR1,VAR2,...
% NCLEAR('VAR1','VAR2',...) clears all the other variables except VAR1,VAR2,...
% NCLEAR() clears all the variables, save as CLEAR
%
% Qun HAN(Tianjin University,P.R.China)
% http://junziyang.spaces.live.com
% 2009-06-01

tempmat=[tempname,'.mat'];
varnames = '';
for n=1:nargin
	if ~ischar(varargin{n})
		varnames = [varnames,'',inputname(n),' ']; %#ok<AGROW>
	else
		varnames = [varnames,varargin{n},' ']; %#ok<AGROW>
	end
end
evalin('caller',['save ',tempmat,' ',varnames]);
evalin('caller','clear');
evalin('caller',['load ',tempmat]);
delete(tempmat);
end

Contact us at files@mathworks.com