How to overwrite some workspace variables in a dynamic program?

31 ビュー (過去 30 日間)
Sophia
Sophia 2012 年 7 月 3 日
Hello,
I have a dynamic program that creates objects in the workspace (datasets, matrices) with the same name each loop but the objects themselves change size each time. Each loop I save them to a data structure and don't want to clear out the workspace. What is the best practice for "overwriting"? Ideas I have are: 1) create a new initialized matrix each time with zeros to wipe out the old matrix or 2) remove the matrix with MLDeleteMatrix(var_name) but this doesn't seem to work with my version (R2011b).

採用された回答

Kye Taylor
Kye Taylor 2012 年 7 月 3 日
Both ideas are good. If 2. doesn't work, try
clear('var_name')
or
clear var_name

その他の回答 (1 件)

Ken Atwell
Ken Atwell 2012 年 7 月 3 日
You can just reassign the variable with new content, MATLAB try to merge the new content with the old, nor will it leak memory.
>> A=ones(100);
>> size(A)
ans =
100 100
>> A=ones(25);
>> size(A)
ans =
25 25

カテゴリ

Help Center および File ExchangeMatrix and Vector Construction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by