Clearing vectors with a certain size

1 回表示 (過去 30 日間)
Danielle Leblance
Danielle Leblance 2017 年 2 月 16 日
回答済み: KSSV 2017 年 2 月 16 日
Is it possible to clear from the workspace all variables that don't meet a certain size? for example, I have vectors with a size of 800000x1 . if in the workspace i have vectors with size 750000x1 I want them to be removed in order to save the vectors in a mat file without the redundant vectors that I don't need.

採用された回答

KSSV
KSSV 2017 年 2 月 16 日
v1 = rand(10,1) ;
v2 = rand(50,1) ;
v3 = rand(30,1) ;
v4 = rand(20,1) ;
var = whos ;
for i = 1:length(var)
if var(i).size(1) < 20
clearvars(var(i).name)
fprintf('cleared %s \n',var(i).name)
end
end
Be carefull about array is column vector or row vector. In my example it is column vector.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by