Updated 6 Apr 2023
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 a future version 10.1). That also includes the potential for float rounding errors.
% examples: 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('==',9.14) % returns true only when run on R2023a 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) !!!
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.
Licence: CC by-nc-sa 4.0
Rik (2023). ifversion (https://github.com/thrynae/ifversion/releases/tag/v1.2.0), GitHub. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
- Mathematics and Optimization > Optimization Toolbox > Linear Programming and Mixed-Integer Linear Programming >
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.2.0
See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.1.2
See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.1.1
See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.1.0
See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.0.6
See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.0.5
See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/v1.0.4
See release notes for this release on GitHub: https://github.com/thrynae/ifversion/releases/tag/1.0.3
added 2019b and 2020a, edited syntax, expanded test
more fleshed-out implementation, replacing getversion by ifversion