Compare toolbox release or version to specified string


  • tf = verLessThan(toolbox,version)



tf = verLessThan(toolbox,version) returns logical 1 (true) if the release or version of the toolbox is older than the value specified by version. Otherwise, it returns logical 0 (false). Use this function to write code that runs on multiple versions of MATLAB®, when there are differences in the behavior of the code in the different versions.


collapse all

Write Version-Specific Code

Modify code that runs in MATLAB R2014a, but that generates an error in R2014b or later.

Create two surface plots. The default color palates are different depending on which version of MATLAB you are using.

s1 = surface(magic(5));
s2 = surface(magic(5)*10,'FaceColor','yellow');

Modify surface s2 by the color of the surface underneath. Starting in R2014b, the EraseMode property has been removed from all graphics objects. Replace the EraseMode property with a value of the FaceAlpha property for code running in MATLAB R2014b and later.

if verLessThan('matlab','8.4')
    % -- Code to run in MATLAB R2014a and earlier here --
    s2.EraseMode = 'xor';
    % -- Code to run in MATLAB R2014b and later here --
    s2.FaceAlpha = .25;

Check for Minimum Required Version

Compare the Simulink® version that is running against version 4.0. If the version is earlier than 4.0, display an error message because the feature is not supported.

if verLessThan('simulink','4.0')
    error('Simulink 4.0 or higher is required.')

Check Toolbox Version

Compare the Data Acquisition Toolbox™ version that MATLAB is running against release R2015a.

Find the name of the toolbox folder. Your output depends on the toolboxes installed on your system.

dir([matlabroot '/toolbox/d*'])
   daq        database   des      distcomp   dotnetbuilder
   dastudio   datafeed   dials    dml        dspblks

Use the toolbox folder name, daq.

ans =


Input Arguments

collapse all

toolbox — Name of MATLAB toolbox folderstring

Name of MATLAB toolbox folder, specified as a string. To specify toolbox, find the folder containing the Contents.m file for the toolbox and use that folder name. To see a list of all toolbox folder names, type:

dir([matlabroot '/toolbox'])

If toolbox does not exist, MATLAB displays an error.

Example: 'images'

version — Version number or release to compare againststring

Version number or release of the program or toolbox to compare against, specified as a string. Specify the version number in the form of major[.minor[.revision]], for example '9.2'.

Example: '9.2'

More About

expand all


  • When running MATLAB R2015b or later, you can specify a release string instead of a version number. For example, you can call verLessThan with 'R2015b' instead of '8.6'. In MATLAB R2015b, the verLessThan function always returns false for all released versions.

    The following example displays a disclaimer message based on MATLAB version.

    function myfunc
        % Display warning in future versions of MATLAB
        if ~verLessThan('matlab','R2015b')
            warning('This function has been tested only with MATLAB R2015a and earlier.')
        % Function code 

See Also

| | | | | |

Introduced in R2007a

Was this topic helpful?