在MATLAB中清除类定义 [英] Clearing class definitions in MATLAB

查看:433
本文介绍了在MATLAB中清除类定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令 clear classes 清除当时在内存中加载的所有类定义。

The command clear classes clears all class definitions loaded in memory at that time.

只清除特定的类定义?

编辑:我非常有兴趣从内存中删除特定的类定义

I'm interesting in removing specific class definitions from memory, not class instances.

推荐答案

当我写我的新HPF类时,我遇到了这个问题。所以我尝试了几个事情,因为我在调试新类时,我做了很多更改,然后测试。

I ran into this issue myself when I wrote my new HPF class. So I tried a few things, since as I was debugging the new class I had many changes to make, and then test out.

清除函数没有帮助。我甚至尝试清除hpf。但是清除所有实例似乎这样做。例如:

"Clear functions" does not help. I even tried "clear hpf". But clearing all instances does seem to do so. For example:

>> x = hpf(3);
>> x+2
ans =
5

>> whos
  Name      Size            Bytes  Class     Attributes

  ans       1x1               248  hpf                 
  x         1x1               248  hpf                 
  y         1x1                 8  double              

现在我对类进行了一个简单的修改并保存。

So now I made a trivial change to the class and saved it.

>> z = hpf(17);
Warning: The class file for 'hpf' has been changed; but the change cannot be applied because objects based on the old class file still exist. If you use
those objects, you might get unexpected results. You can use the 'clear' command to remove those objects. See 'help clear' for information on how to remove
those objects. 

>> clear functions
>> clear hpf
>> clear x
>> clear z
>> x = hpf(3);
Warning: The class file for 'hpf' has been changed; but the change cannot be applied because objects based on the old class file still exist. If you use
those objects, you might get unexpected results. You can use the 'clear' command to remove those objects. See 'help clear' for information on how to remove
those objects. 

所以我还是得到一个警告,告诉我MATLAB还有问题。但是,我仍然在内存中有一个容易忘记的HPF实例,ans。

So I still get a warning, telling me that MATLAB still has a problem. However, I still had an HPF instance in memory that is easily forgotten, ans.

>> clear ans
>> clear x
>> whos
  Name      Size            Bytes  Class     Attributes

  y         1x1                 8  double              

>> x = hpf(3);
>> x+23
ans =
26

也是,MATLAB不再给我一个警告。注意,我从来没有发出清除类命令。变量y,a double,仍然存在以证明这一事实。

As long as I removed that instance too, MATLAB no longer gives me a warning. Note that I never had to issue a "clear classes" command. The variable y, a double, still exists to prove that fact.

这篇关于在MATLAB中清除类定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆