views:

231

answers:

2

I am using classes and static methods to 'scope' functions in a namespace, similar to C#. However, every time I add a new method to a class, at first it is not found. I have to restart the MATLAB environment (2007a) for the new methods to be recognised.

Surely there is an 'update' or 'refresh' type command that I can use so that I do not have to restart the MATLAB environment each time I add a function?

+5  A: 

Issuing this call to CLEAR should do it:

clear classes

One unfortunate side effect of this is that it also effectively issues a clear all, which clears all of the variables in the workspace as well (however, this would happen anyway when you close and restart MATLAB). This clearing of the workspace actually serves a purpose, since it will remove any variables of the same type as the old version of your class, which potentially wouldn't work correctly with the new version of your class.

The function REHASH may work, but I doubt it (I think it deals more with file paths than class definitions).

gnovice
That does work, thanks! Is it possible though to do this on an individual class?
Brendan
As far as I know, there's no way to use CLEAR to update individual classes that have been modified. It's all or none! =)
gnovice
Tried rehash, none of the options work. Think that clear classes is the only way, cheers!
Brendan
A: 

try "clear classname"

hash blue
I'm afraid this doesn't work, it accepts it without error but the class is not updated
Brendan