How to Add Local Toolbox to Project

13 次查看(过去 30 天)
Hello
I have developed a local toolbox MyToolbox and installed it via the Add-On manager.
Separately, I have a project MyProject that uses MyToolbox. MyProject executes correctly because the functions from MyToolbox are on the MATLAB path because it is installed as an Add-On.
But when I run the dependency analyzer on MyProject I get warnings that all the files called from MyToolbox are from an unreferenced project. My question is, is that okay? Or should MyToolbox be added as a referenced project? If it is to be added as a referenced project, what path should I use? The MyToolxBox code is being called from whatever the default location is that MATLAB stores Add-On files (which is not within the MyProject directory). When I add the referenced project, should I specify an absolute to the Matlab Add-On location?
Or is it okay that it remains as an unreferenced project, and it will somehow be communicated by the MATLAB project files that a requirement of MyProject is that MyToolbox has to be installed?

回答(1 个)

Karanjot
Karanjot 2024-2-6
Hi,
It's technically okay for your project to work without referencing the external toolbox as a project, as long as the toolbox is installed and properly set up on the MATLAB path. However, this setup lacks explicit documentation of dependencies, which can be problematic for maintaining, sharing, or deploying the project.
In case you plan to share the project to collaborate with others, I recommend following Best Practices for MATLAB Toolbox Development. By following these best practices, All files you added when you packaged the toolbox are included in the MLTBX file. When the end users install your toolbox, they do not need to be concerned with the MATLAB path or other installation details. The MLTBX file manages these details for end users.
After packaging the toolbox into a single (.mltbx) installation file, Ensure that users of MyProject know about the dependency on MyToolbox. You should document it in the project. This can be done by:
  • Adding a README file with instructions on how to install MyToolbox.
  • Using MATLAB's project features to create a startup file that checks for the presence of MyToolbox and provides instructions if it is not found.
Here are some links you might find useful:
  2 个评论
MATLABNuke
MATLABNuke 2024-2-6
Thank you for the response! It will be important for my collaborators to reproduce MyProject exactly including the dependency of MyToolBox.
I have been following that guide actually, and it is what lead me to this question. I do want to include MyToolBox but I have to specify a path/location in order to add it to the MyProject files. So what path to the code of MyToolBox should I specify? The local one I've been using to develop the code in MyToolBox or the path to the default install location where MATLAB puts Add-Ons?
Specifically, from the guidelines
"What to include: When you package, include all the contents in the toolbox folder, nothing else -- no exclusions, no extra stuff. Make sure that you include all your apps in the apps section of the packaging dialog."
I'm confused on how to add the MyToolBox code.
Or do I not include it? Then when someone wants to run MyProject they get an error or warning indicating that you must also have version XXX of MyToolBox installed?
Karanjot
Karanjot 2024-2-8
"To ensure MATLAB detects the expected components, review the toolbox contents. The following sections of the Package a Toolbox dialog box appear after you select a toolbox folder.
List of the folders and files contained in your toolbox. The listed files and folders are only those files that are located in the top level of the toolbox folder. You cannot navigate through the folders in the Toolbox Packaging dialog box.
By default, if your toolbox contains a P-code file and a MATLAB code file (.m) with the same name in the same folder, MATLAB excludes the .m file from the toolbox. To include both the .p and .m files, clear the Exclude MATLAB script or function files with matching P-files option.
To exclude other files or folders from the toolbox, register them in the text file that is displayed when you click Exclude files and folders. It is good practice to exclude any source control files related to your toolbox."
As for the Path, I believe once a packaged toolbox is installed, you won't need to add the path manually.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by