tags:

views:

1168

answers:

3

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 message when someone attempts to run a script without a required toolbox.

A quick, albeit rough, solution that comes to mind is parsing the text output of the ver command. I wonder if there's a better way.

Some quick searching revealed ver product or the license function with the 'test' argument may be useful, but I could not find a mapping of toolbox names (ie. 'Image Processing Toolbox') to product names (ie. 'control') or feature names (ie. image_toolbox).

Furthermore, when I ran license('inuse'), I only received the following:

>> a = license('inuse'); a

a = 

    feature: 'matlab'
       user: <username>

I hoped for a list of the many toolboxes I have access to.

This question was prompted by trying to test a co-workers script early. Unfortunately, it required the Image Processing Toolbox, which I currently lack. A useful error message would've saved time trying to diagnose the problem. Now I'll wait for a compiled version before testing it.

A: 

a quick way is to list the contents of the toolboxes directory:

l = ls( toolboxdir('') )

using that list (excluding a few directories: shared,local), you can find out the version installed of a toolbox using ver:

v = ver('nnet')

as a reference, here's a list of the toolboxes directory names I had:

bioinfo 
curvefit
database
gads    
ident   
images  
nnet    
optim   
pde     
signal  
stats   
wavelet 
Amro
+2  A: 

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.

Jonas
Thanks for pointing out verLessThan.
vlee
+5  A: 

One drawback to the VER function is that it only tells you what's installed, not what has an available license. It's possible to have a toolbox installed and no license to use it (or all the available licenses could be checked out by other users). A better choice is the LICENSE function, which (as you pointed out) requires a unique "feature string" for each toolbox.

There's a list of feature strings for various toolboxes on this newsgroup thread:

featureStr = {'Aerospace_Blockset'; ...
              'Aerospace_Toolbox'; ...
              'Bioinformatics_Toolbox'; ...
              'Communication_Blocks'; ...
              'Communication_Toolbox'; ...
              'Compiler'; ...
              'Control_Toolbox'; ...
              'Curve_Fitting_Toolbox'; ...
              'Data_Acq_Toolbox'; ...
              'Database_Toolbox'; ...
              'Datafeed_Toolbox'; ...
              'Dial_and_Gauge_Blocks'; ...
              'Distrib_Computing_Toolbox'; ...
              'Econometrics_Toolbox'; ...
              'EDA_Simulator_Link_DS'; ...
              'Embedded_Target_c166'; ...
              'Embedded_Target_c2000'; ...
              'Embedded_Target_c6000'; ...
              'Embedded_Target_MPC555'; ...
              'Excel_Link'; ...
              'Filter_Design_HDL_Coder'; ...
              'Filter_Design_Toolbox'; ...
              'Fin_Derivatives_Toolbox'; ...
              'Financial_Toolbox'; ...
              'Fixed_Income_Toolbox'; ...
              'Fixed_Point_Toolbox'; ...
              'Fixed-Point_Blocks'; ...
              'Fuzzy_Toolbox'; ...
              'GADS_Toolbox'; ...
              'IDE_Link_MU'; ...
              'Identification_Toolbox'; ...
              'Image_Acquisition_Toolbox'; ...
              'Image_Toolbox'; ...
              'Instr_Control_Toolbox'; ...
              'Link_for_Incisive'; ...
              'Link_for_ModelSim'; ...
              'Link_for_Tasking'; ...
              'Link_for_VisualDSP'; ...
              'MAP_Toolbox'; ...
              'MATLAB'; ...
              'MATLAB_Builder_for_dot_Net'; ...
              'MATLAB_Builder_for_Java'; ...
              'MATLAB_Distrib_Comp_Engine'; ...
              'MATLAB_Excel_Builder'; ...
              'MATLAB_Link_for_CCS'; ...
              'MATLAB_Report_Gen'; ...
              'MBC_Toolbox'; ...
              'MPC_Toolbox'; ...
              'NCD_Toolbox'; ...
              'Neural_Network_Toolbox'; ...
              'OPC_Toolbox'; ...
              'Optimization_Toolbox'; ...
              'PDE_Toolbox'; ...
              'Power_System_Blocks'; ...
              'Real-Time_Win_Target'; ...
              'Real-Time_Workshop'; ...
              'RF_Blockset'; ...
              'RF_Toolbox'; ...
              'Robust_Toolbox'; ...
              'RTW_Embedded_Coder'; ...
              'Signal_Blocks'; ...
              'Signal_Toolbox'; ...
              'SimBiology'; ...
              'SimDriveline'; ...
              'SimElectronics'; ...
              'SimEvents'; ...
              'SimHydraulics'; ...
              'SimMechanics'; ...
              'Simscape'; ...
              'SIMULINK'; ...
              'Simulink_Control_Design'; ...
              'Simulink_Design_Verifier'; ...
              'Simulink_HDL_Coder'; ...
              'Simulink_Param_Estimation'; ...
              'SIMULINK_Report_Gen'; ...
              'SL_Verification_Validation'; ...
              'Spline_Toolbox'; ...
              'Stateflow'; ...
              'Stateflow_Coder'; ...
              'Statistics_Toolbox'; ...
              'Symbolic_Toolbox'; ...
              'SystemTest'; ...
              'Video_and_Image_Blockset'; ...
              'Virtual_Reality_Toolbox'; ...
              'Wavelet_Toolbox'; ...
              'XPC_Embedded_Option'; ...
              'XPC_Target'};

Using this list and the function LICENSE, you can check which toolboxes you have a license to use. The following code checks for licenses for the entire list above:

index = cellfun(@(f) license('test',f),featureStr);
availableFeatures = featureStr(logical(index));

However, the above just confirms that the license exists, not that it can be checked out. The license could have expired or all the available licenses could be checked out by other users. To be absolutely certain that you will be able to use the available toolboxes, you can actually try to check out a license for the ones you need and test to see if you were successful. The following code attempts to check out a license for all the available toolboxes found above:

index = cellfun(@(f) license('checkout',f),availableFeatures);
checkedOutFeatures = availableFeatures(logical(index));

NOTE:

As Jason S mentions in a comment below, it's a bad idea to check out licenses willy-nilly, since they won't be released until you close MATLAB. You should only check out a license that you know you will need for a given application! Normally, licenses aren't checked out until you try to use a function from a given toolbox. For example:

>> license('inuse')
matlab
>> gaussFilter = fspecial('gaussian');  %# An Image Processing Toolbox function
>> license('inuse')
image_toolbox
matlab
gnovice
I guess the best method would be to use both the ver and the license command. This way, you can inform the user whether they lack a toolbox altogether, or whether they simply need to wait/scream until the license becomes available.
Jonas
Note that checking out a license just to see if you can check out a license is a **bad** thing because in MATLAB the license will not and cannot be released until you close MATLAB altogether. This does not "play nicely" with shared licensing (especially given Mathworks' poor pricing for network license toolboxes)
Jason S
(however if you need to use that toolbox anyway in the function it should be fine)
Jason S
@Jason: You're right. Checking out a license just to see if you *can* is a bad thing. I was only suggesting doing it for the case when you will actually *need* it, but I don't think I made that point clearly. I'll clarify it.
gnovice
Thank you all very much for the responses. This definitely helps me understand MATLAB's licensing scheme better (especially explaining my 'inuse' output). It's a pity that there's no way to release a license without exiting though.
vlee
Additionally, thanks to the explanation of 'inuse', I can now get the feature name for any toolbox I have by simply using a function from the toolbox then running license('inuse'). Hmm, markup doesn't work for comments, doh! Here's an inline example: fmdemod(ones(1,100), 10, 20, 1); license('inuse'). That returns: communication_toolbox, matlab, signal_toolbox
vlee

related questions