How would one check for installed MATLAB toolboxes in a script/function?

后端 未结 6 584
孤独总比滥情好
孤独总比滥情好 2020-12-13 02:36

How would one check for installed MATLAB toolboxes in a script/function? (checking toolbox versions would also be good!) This could provide a quick and useful error messag

6条回答
  •  没有蜡笔的小新
    2020-12-13 03:17

    Ver seems like the way to go, and parsing shouldn't be that hard. Let's see:

    function tf = areTheseToolboxesInstalled(requiredToolboxes)
    %ARETHESETOOLBOXESINSTALLED takes a cell array of toolbox names and checks whether they are currently installed
    % SYNOPSIS tf = areTheseToolboxesInstalled(requiredToolboxes)
    %
    % INPUT requiredToolboxes: cell array with toolbox names to test for. Eg. 
    %        {'MATLAB','Image Processing Toolbox'}
    %
    % OUTPUT tf: true or false if the required toolboxes are installed or not
    %%%%%%%%%%%%%%%%%%%%%%%%%%
    
    % get all installed toolbox names
    v = ver;
    % collect the names in a cell array
    [installedToolboxes{1:length(v)}] = deal(v.Name);
    
    % check 
    tf = all(ismember(requiredToolboxes,installedToolboxes));
    

    By the way, if you need to check for versions, verLessThan is your friend.

提交回复
热议问题