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 '18.104.22.168935 (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.
Tim Davis (2021). getversion (https://www.mathworks.com/matlabcentral/fileexchange/17285-getversion), MATLAB Central File Exchange. Retrieved .
Here's another way that avoids the problems described by the author
v = ver('Matlab');
v = str2double(v.Version);
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.
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 ...
Relatively simple, but hey - I'm lazy. Seems solid. Thanks.
Inspired by: vernum.m
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!