Check for dependencies and download required toolbox
10 次查看(过去 30 天)
显示 更早的评论
Hi all. I'm working on a script that uses a function packaged with the Computer Vision toolbox. However, some team members have experienced errors with my script because they didn't have the Computer Vision toolbox installed.
Is there a way I can...
- check if the person running the script has this toolbox installed
- If it's not installed, install it via the command window
Any help would be appreciated. Thanks!
0 个评论
采纳的回答
Image Analyst
2022-1-17
Call this function in your startup code, before anything else runs:
% List required files and toolboxes. Displays them in the command window or console window (if deployed).
% Sample call
% fullFileName = [mfilename('fullpath'), '.m'];
% DisplayRequiredFunctions(fullFileName)
% It takes a long time to run so that's why I only do it in the development environment.
function DisplayRequiredFunctions(fullFileName)
try
if ~isdeployed
[~, baseFileNameNoExt, ext] = fileparts(fullFileName);
baseFileName = [baseFileNameNoExt, '.m'];
[requiredFileList, toolboxList] = matlab.codetools.requiredFilesAndProducts(fullFileName);
fprintf('Required m-files for %s:\n', baseFileName);
for k = 1 : length(requiredFileList)
fprintf(' %s\n', requiredFileList{k});
end
fprintf('Required MATLAB Toolboxes for %s:\n', baseFileName);
for k = 1 : length(toolboxList)
fprintf(' %s\n', toolboxList(k).Name);
end
end
catch ME
end
Also, you can put this code there:
% Check that user has the specified Toolbox installed and licensed.
%hasLicenseForToolbox = license('test', 'image_toolbox'); % Check for Image Processing Toolbox.
% hasLicenseForToolbox = license('test', 'Image_Acquisition_Toolbox'); % Check for Image Acquisition Toolbox.
% hasLicenseForToolbox = license('test', 'Statistics_Toolbox'); % Check for Statistics and Machine Learning Toolbox.
% hasLicenseForToolbox = license('test', 'Signal_Toolbox'); % Check for Signal Processing Toolbox.
hasLicenseForToolbox = license('test', 'Video_and_Image_Blockset'); % Check for Computer Vision System Toolbox.
% hasLicenseForToolbox = license('test', 'Neural_Network_Toolbox'); % Check for Deep Learning Toolbox.
if ~hasLicenseForToolbox
% User does not have the toolbox installed, or if it is, there is no available license for it.
% For example, there is a pool of 10 licenses and all 10 have been checked out by other people already.
ver % List what toolboxes the user has licenses available for.
message = sprintf('Sorry, but you do not seem to have the Computer Vision Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
更多回答(1 个)
Pratyush Roy
2022-1-17
Hi Daniel,
- To check whether the person has the toolbox installed, the ver command can be used which shows the list of installed toolboxes in the current MATLAB installation.
- For installing additional toolboxes to the existing installation, please refer to the steps mentioned in this link
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!