clearvars
- clearvars removes all variables defined in running session
- clearvars('-except', vars) removes all variables except the ones specified in vars, which can be either a char object or a cell array of strings
Examples
>> a = 1; b = 2; c = 3; d = 4;
[a:1]
[b:2]
[c:3]
[d:4]
>> clearvars('-except', {'a'; 'b'}) % clear variables c and d
>> c#
undefined function or variable "c" - line 1
>> clearvars('-except', 'a') % keep only variable a
>> var = whos#
[a:1]