Can Matlab packages have subdirectories?
I'd like to organize my Matlab packages into folders. However, if I try to lay out my code like this
+MyPackage |---foo.m |---SubDir |---bar.m
then I'm unable to reach bar. For example, if the contents of foo.m are
function foo disp("foo") bar end
and the contents of bar.m are
function bar disp("bar") end
foo Error using bar Not enough input arguments. Error in MyPackage.foo (line 3) bar
Trying to add SubDir with
addpath gives a warning that package directories are not allowed in the MATLAB path. Does everything in a Matlab package really need to be within a single directory, or is there a way to organize packages with subdirectories?
Well, minutes after posting my question, I found the disappointing answer: no.
Original answer found on https://www.mathworks.com/matlabcentral/answers/184191-can-i-have-subdirectories-in-a-package-directory from Jim Svensson.
His suggested workaround is to have multiple packages with the same name, but placed in different directories, like so:
0 comment threads