Can I have subdirectories in a +package directory?

32 visualizaciones (últimos 30 días)
Richard Crozier
Richard Crozier el 20 de Mzo. de 2015
Comentada: Jim Svensson el 14 de Mayo de 2019
I would like to know if it is possible to add subdirectories to a matlab package directory (denoted by a preceeding '+' in the directory name). Often I want to split up my functions within a package into logical units in directories, but without needing them to each have their own subnamespace. In other words, is it possible to have:
and have both called in my matlab code as:
My tests indicate this is not possible (at least in 2014a). Is this impossible, and if so, is there some technical reason it could not be implemented by TMW?
  2 comentarios
Jim Svensson
Jim Svensson el 14 de Mayo de 2019
The mechanism you want does not exist. But you achieve a similar thing by putting the differrent folder groups first and multiple packages of the same name inside, like so:
d = pkg_foo.find_data();

Iniciar sesión para comentar.

Respuesta aceptada

Richard Crozier
Richard Crozier el 19 de Nov. de 2018
The answer is no, you cannot have subdirectories in a package directory.

Más respuestas (2)

Philip Joergensen
Philip Joergensen el 15 de Nov. de 2018
Not sure why it does not make sense to place both functions in the root of the package in the case you describe.
I figured out, if you do not mind having a namespace for each subdirectory, you can have subpackages in your package:
And then calling the lowerlevelfun would be
Which seems to make good sense in this use case, as it is easy to group functions into easy to remember and meaningful namespaces.
  3 comentarios
Richard Crozier
Richard Crozier el 19 de Nov. de 2018
Do you mean effort for the user? The user can just do

Iniciar sesión para comentar.

Michael Häußler
Michael Häußler el 15 de Nov. de 2018
There is also the possibility to use private folders within the package. The functions/classes within that folder are however only visible to the files within the package....
Still not what you want exactly, but I actually use that a lot now to have small "helper functions" within the package organized at a different place:
  1 comentario
Richard Crozier
Richard Crozier el 19 de Nov. de 2018
Thanks, yes, I'm also aware of this, but this doesn't do what I want at all, since I want the functions to be available through the package namespace. Even if it did do something like what I wanted, as there can naturally only be one private directory, called 'private' in a package directory, it doesn't really help with organisation in any way.

Iniciar sesión para comentar.


Más información sobre Search Path en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by