如何正确命名和组织MATLAB的文件类?

如何正确命名和组织MATLAB的文件类?,matlab,oop,import,package,fully-qualified-naming,Matlab,Oop,Import,Package,Fully Qualified Naming,考虑以下目录结构,并且C:\magic是当前的MATLAB文件夹: C:\magic C:\magic\+wand C:\magic\+hat 现在,wand和hat是MATLAB软件包,可以通过import wand.*和import hat.*加载 考虑一下,我可能想在+hat文件夹中为hat创建一个抽象类: % C:\magic\+hat\Hat.m classdef Hat < handle % class implementation ... end 我得到以下错误:

考虑以下目录结构,并且
C:\magic
是当前的MATLAB文件夹:

C:\magic
C:\magic\+wand
C:\magic\+hat
现在,
wand
hat
是MATLAB软件包,可以通过
import wand.*
import hat.*
加载

考虑一下,我可能想在
+hat
文件夹中为hat创建一个抽象类:

% C:\magic\+hat\Hat.m
classdef Hat < handle
    % class implementation ...
end
我得到以下错误:

Error using hat.TopHat
The specified superclass 'Hat' contains a parse error or cannot be found
on MATLAB's search path, possibly shadowed by another file with the same name.
尽管如此,我仍然可以毫无错误地执行
ha=Hat()

可能发生的情况以及解决该问题的最佳方案是什么

提前谢谢

试试看

classdef (Sealed) TopHat < hat.Hat
classdef(密封)顶帽

MATLAB中没有“先搜索当前包”例程(很抱歉这个坏名字:>)。因此,要在一个包中引用一个类,您必须始终携带包名,即使是在自己的classdef中引用一个类的静态方法

对!!我在提出这个问题后不久就试过了,结果成功了。。。我认为MATLAB很无组织,不是吗?这种问题不应该发生……与本机面向对象编程语言相比,事情有时似乎有点人为。但是,在我的印象中,MATLAB中的OOP仍然非常少见。我认为这可以归咎于MATLAB中的导入功能。。。它有点原始。如果你想一想有效的语法,Matlab需要理解它的作用域,而不是在同一个包中,等等。。。希望有一天Mathworks会让这个问题变得更好
Error using hat.TopHat
The specified superclass 'Hat' contains a parse error or cannot be found
on MATLAB's search path, possibly shadowed by another file with the same name.
classdef (Sealed) TopHat < hat.Hat