Add toolboxes subfolders to Matlab path when packaging

19 visualizaciones (últimos 30 días)
I have created a toolbox called Alexandria. Basically the toolbox is contained into a root folder called alexandria which contains one subfolder (also called alexandria) that itself stores other subfolders containing all the functions and scripts needed for the toolbox. The root folder also contains two scripts (alexandria_gui.m and alexandria_ide.m) which can also call functions from the alexandria subfolder:
alexandria --> alexandria_gui.m
--> alexandria_ide.m
--> alexandria --> linear_regression (includes LinearRegression.m, SimpleBayesianRegression.m ...)
--> processor (includes InputProcessor.m, RegressionProcessor.m ...)
--> and so on...
I want to create a toolbox that makes all the scripts and functions available to the user from the console, and not just the two scripts alexandria_gui.m and alexandria_ide.m that are in the root folder. However, when I try to package the toolbox from root alexandria folder, I obtain the following:
the "Toolbox Files and Folders" part shows that the packager finds the two scripts and the alexandria subfolder in the root folder. Fine. The "External Files" says that "No files outside of the toolbox folder are required". This is fine IF that means that all the subfolders in the root folders (in particual the alexandria subfolder) are also included in the packaging and added to the Matlab path, which I am not sure. Indeed, "Install Actions" clearly shows that only the root folder <Toolbox Folder> will be added to the MATLAB path. So seemingly none of the subfolders will be added to the Matlab path at installation, though the subfolders themselves will be packaged and installed. In my case however, packaging the subfolders but not adding them to the Matlab path is pointless, as my toolbox will not detect them and hence not work properly.
So my question is simply; is there a way to force the packager to add all the subfolders to the path when installing? And by the way, how is it that Matlab seems unable to detect subfolder dependencies, which represent elementary software architecture?
As it is, it seems that forcing addition of undetected subfolders to the Matlab path is not possible. The only solution (that I mentioned on a similar subject here) then seems to add the folders to the path manually after installation, which sounds bad. So, is there any solution?
Note: the packager seems unstable. Sometimes in the past I managed to get the dependencies detected, and this way I could upload one version of my software on File Exchange. But now, after an update of my toolbox, the packager just seems unable to propose to add any dependency to the path.

Respuesta aceptada

Romain Legrand
Romain Legrand el 16 de Ag. de 2022
So, I eventually found the solution to my problem. It comes from this short line in the documentation:
"MATLAB Path — List of folders that are added to the user’s MATLAB path when they install a toolbox. By default, the list includes any of the toolbox folders that are on your path when you create the toolbox."
So, to add your toolbox subfolders to the Matlab path at installation, one needs to:
- add first all the toolbox subfolders to the current path; this can be done e.g. by setting the Matlab current folder to your toolbox root folder, then use the command : addpath(genpath(pwd))
- package the toolbox as usual; normally, the "Install actions" section of the packager should display all the subfolders, showing that they are properly added to the path at installation.

Más respuestas (1)

Image Analyst
Image Analyst el 16 de Ag. de 2022
Maybe just add it to the path if it's not already there. Like if you're running one of your functions, call this early on
p = path;
if ~contains(p, '\alexandria\alexandria')
% Subfolders are not yet on the path so add them.
folder = fileparts(which('alexandria.m')); % Determine where folder is.
pSubFolders = genpath(folder); % Get path to all subfolders.
addpath(pSubFolders) % Add subfolders to the path.
savepath; % Save it for next session.
end
  3 comentarios
Image Analyst
Image Analyst el 16 de Ag. de 2022
I don't use the MATLAB deploytool or whatever you're using. I use a third party installation package building program called Centurion Setup. That would be able to do it - I'd do it by having it modify the startup.m file to add addpath(genpath(toolboxFolder)) to the startup code. If you want to continue to use the Mathwork installer you'll have to call them and ask them if there is a "with subfolders" option to the path modification step.
Romain Legrand
Romain Legrand el 16 de Ag. de 2022
Okay, thanks a lot for the precisions. It is sad that Mathworks seemingly does not allow for something as basic as a subfolder architecture in their toolbox manager. I guess the only solution with the packager at the moment remains the post installation manual addition of the subfolders to the Matlab path.

Iniciar sesión para comentar.

Categorías

Más información sobre Introduction to Installation and Licensing 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