File Exchange

image thumbnail

getversion

version 1.1.0.0 (2.22 KB) by Tim Davis
Portable replacement for verLessThan on old MATLAB releases

1 Download

Updated 20 Nov 2014

View License

getversion returns the MATLAB version number as a double, to allow inequality comparisons when checking for ranges of MATLAB versions. The major, sub, and sub-sub version numbers are returned (MATLAB '6.5.2.202935 (R13) Service Pack 2' returns 6.52).
This code is more portable than "ver" (which verLessThan uses) because it does not use structs. It should work on any MATLAB that has the version, sscanf, and length functions.

It has been tested on MATLAB 6.1, 6.5.2., 7.0.1, 7.0.4, 7.1, 7.2, 7.3, 7.4, and 7.5. I no longer have MATLAB 5.x or earlier; please notify me if you test it on those platforms.

See also ver, version, and verLessThan.

Cite As

Tim Davis (2019). getversion (https://www.mathworks.com/matlabcentral/fileexchange/17285-getversion), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

Adam Danz

Here's another way that avoids the problems described by the author
v = ver('Matlab');
v = str2double(v.Version);

Adam Danz

Jan

I'm using 13.1 (for R13SP1), ..., 2009.1, 2009.2, 2010.1 instead. This is monotonically increasing and will be consistent until TMW delivers a J release... But to be true: This is also just another strange try to live with Matlab's funny numbering methods.

Tim Davis

Comment from the author:

Note that for MATLAB 7.10 (R2010a), this function returns "8". Version 7.10 follows after 7.9, but version 7.10 is not the same as 8.0. When I wrote this code, I assumed that the subversion number (the "y" in "x.y") would always be a single decimal digit.

getversion still returns a value that is monotonically increasing for all MATLAB versions, including 7.10. However, it will fail when MATLAB 8.0 actually comes out.

One fix would be to return a value equal to version+subversion/100, so that "7.1" becomes the number 7.01, "7.10" becomes the number 7.1, and "8.0" would then be 8.0. But this fix would look strange. Printing the version number would lead to confusion.

Maybe I should switch to hexadecimal ...

Pete

Relatively simple, but hey - I'm lazy. Seems solid. Thanks.

Updates

1.1.0.0

Update to comments. No resolution of 7.10 = 8 problem...

1.0.0.0

minor typo in description (no change to code)

MATLAB Release Compatibility
Created with R12.1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: vernum.m