ifversion

Version 1.2.1.2 (9,06 ko) par Rik
Determine if the current version satisfies a version restriction
44 téléchargements
Mise à jour 23 mars 2024

ifversion documentation

View ifversion on File Exchange Open in MATLAB Online

Table of contents

Description

This minitool helps you determine the version of Matlab (or Octave) that is running your code. This is helpful when imposing a minimum version requirement, or when different versions need different methods to reach the same end result. By using persistent variables this will stay fast even with repeated calls.

You shouldn't use a logical test with v=version;v=str2double(v(1:3)); as it is incomplete for several releases (like e.g. 7.14 or 23.2). That also includes the potential for float rounding errors.

If you don't want to use a separate function, there are two built-in functions that may do what you need: verLessThan (introduced in R2007a) and isMATLABReleaseOlderThan (introduced in R2020b). The latter also allows filtering based on release type (pre-release vs normal release) and update number.

Matlab/Octave

Syntax

tf=ifversion(test,Rxxxxab)
tf=ifversion(test,Rxxxxab,'Octave',test_for_Octave,v_Octave)

Output arguments

Argument Description
tf If the current version satisfies the test this returns true.
This works similar to verLessThan.

Input arguments

Argument Description
test Char array containing a logical test. The interpretation of this is equivalent to eval([current test Rxxxxab]). For examples, see below.
Rxxxxab Char array containing a release description (e.g. 'R13', 'R14SP2' or 'R2019a') or the numeric version. Note that 9.10 is interpreted as 9.1 when using numeric input.
test_for_Octave See the test parameter. If not provided, the same test will run on GNU Octave as on Matlab. This will also trigger a warning.
v_Octave The numeric version of Octave. If not provided, the same test will run on GNU Octave as on Matlab. This will also trigger a warning.

Examples

A few examples of valid syntax options:

    ifversion('>=','R2009a')        % returns true when run on R2009a or later
    ifversion('<','R2016a')         % returns true when run on R2015b or older
    ifversion('==','R2018a')        % returns true only when run on R2018a
    ifversion('==',24.01)           % returns true only when run on R2024a
    ifversion('<',0,'Octave','>',0) % returns true only on Octave
    ifversion('<',0,'Octave','>=',6)% returns true only on Octave 6 and higher
    ifversion('==',9.10)            % !!! returns true only when run on R2016b (v9.1), not R2021a (v9.10) !!!

Compatibility, version info, and licence

Compatibility considerations:

  • This is expected to work on all releases.
Test suite result Windows Linux MacOS
Matlab R2024a W11 : Pass Monterey : Pass
Matlab R2023b ubuntu_22.04 : Pass Monterey : Pass
Matlab R2023a W11 : Pass
Matlab R2022b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2022a W11 : Pass
Matlab R2021b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2021a W11 : Pass
Matlab R2020b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2020a W11 : Pass
Matlab R2019b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2019a W11 : Pass
Matlab R2018b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2018a W11 : Pass
Matlab R2017b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2016b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2015a W11 : Pass
Matlab R2013b W11 : Pass
Matlab R2007b W11 : Pass
Matlab 6.5 (R13) W11 : Pass
Octave 8.4.0 W11 : Pass
Octave 8.2.0 W11 : Pass
Octave 7.2.0 W11 : Pass
Octave 6.2.0 W11 : Pass ubuntu_22.04 : Pass Catalina : Pass
Octave 5.2.0 W11 : Pass
Octave 4.4.1 W11 : Pass Catalina : Pass
Version: 1.2.1.2
Date:    2024-03-23
Author:  H.J. Wisselink
Licence: CC by-nc-sa 4.0 ( https://creativecommons.org/licenses/by-nc-sa/4.0 )
Email = 'h_j_wisselink*alumnus_utwente_nl';
Real_email = regexprep(Email,{'*','_'},{'@','.'})

Test suite

The tester is included so you can test if your own modifications would introduce any bugs. These tests form the basis for the compatibility table above. Note that functions may be different between the tester version and the normal function. Make sure to apply any modifications to both.

Citation pour cette source

Rik (2024). ifversion (https://github.com/thrynae/ifversion/releases/tag/v1.2.1.2), GitHub. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2024a
Compatible avec les versions R13SP1 et ultérieures
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur Linear Programming and Mixed-Integer Linear Programming dans Help Center et MATLAB Answers
Tags Ajouter des tags

Community Treasure Hunt

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

Start Hunting!
Version Publié le Notes de version
1.2.1.2

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.2.1.2

1.2.1.1

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.2.1.1

1.2.1.0

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.2.1

1.2.0.0

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.2.0

1.1.2

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.1.2

1.1.1

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.1.1

1.1.0

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.1.0

1.0.6

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.0.6

1.0.5

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.0.5

1.0.4

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.0.4

1.0.3

See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/1.0.3

1.0.2

added 2019b and 2020a, edited syntax, expanded test

1.0.1

more fleshed-out implementation, replacing getversion by ifversion

1.0.0

Pour consulter ou signaler des problèmes liés à ce module complémentaire GitHub, accédez au dépôt GitHub.
Pour consulter ou signaler des problèmes liés à ce module complémentaire GitHub, accédez au dépôt GitHub.