How to clear classes except some variables?
11 ビュー (過去 30 日間)
古いコメントを表示
I am looping through a code which generates a class with different parameters every time.In every loop i erase the previous classes but i want some values to remain.Unfortunaltely the code i am using erase all the values.To be more clear a simple example follows:
for ii=1:24
clear classes -except Cp ii input;
output = className(input(ii));
Cp(ii) = output.Cp;
end
Any idea what i am doing wrong?Or is there another way to impliment it? Thanks in advance.
0 件のコメント
回答 (2 件)
Guillaume
2014 年 11 月 12 日
No, clear classes also clear all variables, and there's no way around it.
However, clearing classes in a loop sounds very odd. Why are you doing this and what are you trying to achieve? The only reason you'd want to clear classes would be if the code had changed while some objects are still in memory (I'm not even sure you need to do that in 2014b anymore). This is obviously not the case in your example.
0 件のコメント
Sean de Wolski
2014 年 11 月 12 日
You shouldn't have to clear classes, this is a nuclear hammer approach. You need to clear classes when you the blueprint of the class, i.e. the class definition file has changed. To clear a specific variable just clear it. To clear a specific class, clear just that class.
clear A classA
Still, unless you're changing the text of the class definition, clearing the class should be unnecessary.
1 件のコメント
Lockywolf
2018 年 1 月 11 日
I am modifying class code in process.
My code essentially has several class definitions and for every problem loops through them finding the best one, and substitutes the name for the actually used class.
Is there a way to clear class definitions, desirably for selected classes only?
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!