Why do I get an error after adding a method to a class in MATLAB 7.7 (R2008b)?

1 view (last 30 days)
I created a class called MyClass, which is stored in a file as follows:
..\@MyClass\MyClass.m
Then I create a function called myfunction.m and store the file in the folder @MyClass. When I execute the following:
myObj = MyClass
myfunction(myObj)
I get the following error:
Undefined function or method 'myfunction' for input arguments of type 'MyClass'.
I need to restart MATLAB for the function call to work properly. I would like for MATLAB to be automatically able to detect the new functions.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Jun 2020
Edited: MathWorks Support Team on 25 Jun 2020
The ability to automatically detect new functions or methods stored in separate files is not available in MATLAB 7.7 (R2008b).
To work around this issue, you have two options:
1. Declare the method signature within a methods block in the classdef block as specified in the 'Methods in Separate Files' section of the documentation found by executing the following at the MATLAB Command Prompt:
web([docroot '/techdoc/matlab_oop/brdqinq.html#brdqipw-1'])
For example:
classdef MyClass
methods (AttributeName = value,...)
tdata = myfunction(obj,arg1,arg2)
...
end % methods
...
end % classdef
2. After creating the function file, execute either of the following two commands to clear the class/function cache:
clear classes
clear functions

More Answers (0)

Categories

Find more on Class File Organization in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2008b

Community Treasure Hunt

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

Start Hunting!