I have a thousands of variables stores in .mat files. I am loading them in a loop one at a time. I then assign the loaded variable the workspace variable x
using eval
. Then, I clear the loaded variable. The problem is that matlab gives The current workspace already has too many variables
error after around 60,000 iterations. But, on checking the workspace, it appears that only 5-10 variables are present.
for i = 1:m
load(sprintf('feat_%s.mat', ids{i}), sprintf('feat_%s', ids{i}));
eval(sprintf('x = feat_%s;', ids{i}));
clear(sprintf('feat_%s', ids{i}));
end
I think this has got to do with the eval
command. I am guessing that eval
is creating multiple copies of x
. Any idea on wow to clear variables created using eval
.