Check for dependencies and download required toolbox

조회 수: 17 (최근 30일)
Daniel Oberbauer
Daniel Oberbauer 2022년 1월 13일
댓글: Daniel Oberbauer 2022년 2월 4일
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...
  1. check if the person running the script has this toolbox installed
  2. If it's not installed, install it via the command window
Any help would be appreciated. Thanks!

채택된 답변

Image Analyst
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
Pratyush Roy 2022년 1월 17일
Hi Daniel,
  1. 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.
  2. For installing additional toolboxes to the existing installation, please refer to the steps mentioned in this link
Hope this helps!

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by