필터 지우기
필터 지우기

How to delete workspace empty variables

조회 수: 3 (최근 30일)
xander fong
xander fong 2015년 7월 21일
댓글: bio lim 2015년 7월 21일
Hello, I have a script that creates tons of variables in my workspace. However, some of them are worthless. For example, one will be a 3x1 cell array that is [ [] [] [] ]. How do I delete all these variables that are filled with empty cells?
  댓글 수: 1
xander fong
xander fong 2015년 7월 21일
note that, the variables arent empty themselves. Rather, they are cell arrays of certain dimensions filled with empty cells

댓글을 달려면 로그인하십시오.

답변 (1개)

bio lim
bio lim 2015년 7월 21일
a=who;
for var=1:length(a)
b=eval([a{var}]);
if isempty(b)
eval(['clear ' a{var} ';'])
end
end
clear a b
Source. Also look at here.
  댓글 수: 2
xander fong
xander fong 2015년 7월 21일
not working :/
bio lim
bio lim 2015년 7월 21일
This should work assuming your variables are cell arrays.
c = cell(1,3); % Cell c and e are empty
d = cell(1,2);
e = cell(1,5);
d{1,1} = 4;
d{1,2} = 7;
var = who;
for var_num = 1 : length(var)
if iscell(eval([var{var_num}]))
e = cellfun(@isempty, eval([var{var_num}]));
h = true(size(eval([var{var_num}])));
if isequal(h,e)
eval(['clear ' var{var_num} ';'])
end
end
end
clear var var_num e h
% Remaining variable is d

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by