How to install required add-ons when using matlab.addons.install

When installing an mltbx that has required addons by double clicking on it from the "Current Folder" panel the IDE will tell me about any additional required addons (toolboxes) that needs to be installed and install them as part of the interaction. If the toolbox is already present and has multiple versions available it will change the enabled version to the one that the mltbx requires during install.
I noticed that neither of these things happen if I install a toolbox using the matlab addon or toolbox install apis. I was wondering if there are other APIs that I can use to query an mltbx for it's "Required Add-ons" dependencies as part of an install from the command window (or other non GUI environment) to then pass to additional API install calls, or another way to achieve parity with the mltbx GUI installer functionality in a script environment.
I will note that calling open runs the dialog, but want to confirm this is intended (as mltbx is not on the doc page), and I need to test the behavior in a non interactive environment to see if it will automatically manage the install, or fail since there can be a confirmation dialog.
open("<name>.mltbx")

 Accepted Answer

Yes, you can query an mltbx for its "Required Add-ons" dependencies using MATLAB's matlab.addons.toolbox.toolboxVersion function. This function returns information about a toolbox version, including its required add-ons.
Here's an example of how you can use this function to get the required add-ons for a toolbox:
tbxInfo = matlab.addons.toolbox.toolboxVersion('<name>');
requiredAddons = tbxInfo.RequiredAddons;
This will return a cell array of required add-ons for the specified toolbox. You can then use this information to install the required add-ons using the matlab.addons.toolbox.installToolbox function:
for i = 1:length(requiredAddons)
addonName = requiredAddons{i};
matlab.addons.toolbox.installToolbox(addonName);
end
This will install each required add-on in turn. Note that you may need to provide additional arguments to the installToolbox function to specify installation options (such as installation directory or version) depending on your specific use case.
Regarding your question about calling open in a non-interactive environment, it's possible that this may not work as expected if there are confirmation dialogs or other interactive prompts involved in the installation process. In this case, you may need to use the matlab.addons.toolbox.installToolbox function or other installation APIs to ensure a fully automated installation process.

5 Comments

This is great! Thank you Aishwarya.
Quick follow up. Is there anything I should know about when using the matlab.addons.install api instead of matlab.addons.toolbox.installToolbox api? I prefer using addons.install since I can keep multiple versions installed at the same time and switch the enabled version as needed.
The matlab.addons.install function is a more general-purpose function for installing MATLAB add-ons, which includes toolboxes as well as other types of add-ons such as apps and support packages. It provides more flexibility than matlab.addons.toolbox.installToolbox, as you can use it to install any type of add-on and specify various installation options.
When installing a toolbox with matlab.addons.install, you can use the 'toolbox' value for the 'type' parameter to specify that you are installing a toolbox:
matlab.addons.install(addonFile, 'type', 'toolbox');
You can also use the 'enable' parameter to specify whether to enable the installed toolbox:
matlab.addons.install(addonFile, 'type', 'toolbox', 'enable', true);
If you want to install a specific version of the toolbox, you can use the 'version' parameter:
matlab.addons.install(addonFile, 'type', 'toolbox', 'version', '1.0');
Regarding your preference for using matlab.addons.install over matlab.addons.toolbox.installToolbox because you can keep multiple versions installed at the same time and switch the enabled version as needed, note that you can also achieve this with matlab.addons.toolbox.installToolbox. The installToolbox function supports installing multiple versions of a toolbox, and you can use the matlab.addons.toolbox.toolboxVersion function to get information about the installed versions and enable a specific version:
tbxInfo = matlab.addons.toolbox.toolboxVersion('<name>');
enabledVersion = tbxInfo.EnabledVersion; installedVersions = tbxInfo.Versions;
You can then use the matlab.addons.toolbox.enableToolbox function to enable a specific version:
matlab.addons.toolbox.enableToolbox('<name>', 'version', '1.0');
So, both matlab.addons.install and matlab.addons.toolbox.installToolbox can be used to achieve your desired functionality. The choice between them depends on your specific requirements and use case.
Thanks again Aishwarya. I hadn't picked up from the docs that I could pass a struct to installToolbox, but I see that using help now. This is all really helpful.
Hi @Alexander, I apologise for a overlook, the command:
tbxInfo = matlab.addons.toolbox.toolboxVersion('<name>');
Only returns the version as a char and actually currently there is no documented function to get the dependency information.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!