Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get MATLAB to recognise newly added static methods?

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?

like image 466
Brendan Avatar asked Jul 01 '09 14:07

Brendan


People also ask

How do you call a static method in MATLAB?

To call a static method, prefix the method name with the class name so that MATLAB can determine what class defines the method. Call staticMethod using the syntax classname . methodname : r = MyClass.

How do you invoke a static method?

We can invoke a static method by using its class reference. An instance method is invoked by using the object reference. 5. We can't access instance methods and instance variables with the help of Static methods in Java.

Can static methods be updated?

In simple words, if you use a static keyword with a variable or a method inside a class, then for every instance that you create for that class, these static members remain constant and you can't change or modify them.

Do static methods run automatically?

A static constructor cannot be called directly and is only meant to be called by the common language runtime (CLR). It is invoked automatically. The user has no control on when the static constructor is executed in the program. A static constructor is called automatically.


1 Answers

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

like image 140
gnovice Avatar answered Oct 03 '22 23:10

gnovice