How to access other classes in the same package folder from inside?

5 views (last 30 days)
I created a package folder (like "+mypackage") under the MATLAB folder with several classes in the package, and I would like to let one class to inherit another (all in the same package, same folder), e.g.
./MATLAB/+mypackage/A.m with first line "classdef A"
./MATLAB/+mypackage/B.m with first line "classdef B < A"
However, I get following error when I want to create an instance of B:
The specified superclass 'A' contains a parse error, cannot be found on MATLAB's searchpath, or is shadowed by another file with the same name.
I know that if I want to access these classes from outside of the outside of the package, I should use a syntax like "mypackage.A". Should I use the same syntax from inside of the package? Where did I do wrong?

Accepted Answer

Guillaume
Guillaume on 16 Apr 2015
In my opinion, matlab's packages are not well designed as, indeed, function and classes within the package still have to specify the package name when calling other function or classes in the same package.
So indeed, you have to use:
classdef B < mypackage.A
Hilarity ensues when you want to rename the package.
  1 Comment
Stefan Kiss
Stefan Kiss on 28 Sep 2019
Not the answer we wanted to hear, but the answer we needed none the less.
Dear MATLAB, please fix this.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!