How to clear classes except some variables?

조회 수: 19 (최근 30일)
Dimitrios
Dimitrios 2014년 11월 12일
댓글: Lockywolf 2018년 1월 11일
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.

답변 (2개)

Guillaume
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.

Sean de Wolski
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
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 CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by