1function v = getversion 2%GETVERSION return MATLAB version number as a double. 3% GETVERSION determines the MATLAB version, and returns it as a double. This 4% allows simple inequality comparisons to select code variants based on ranges 5% of MATLAB versions. 6% 7% As of MATLAB 7.10, the version numbers are listed below: 8% 9% MATLAB version getversion return value 10% ------------------------------- ----------------------- 11% 7.10.0.499 (R2010a) 8.0 (this needs to be fixed). 12% 7.9.0.529 (R2009b) 7.9 13% 7.8.0.347 (R2009a) 7.8 14% 7.7.0.xxx (R2008b) 7.7 15% 7.6.0.324 (R2008a) 7.6 16% 7.5.0.342 (R2007b) 7.5 17% 7.4.0.287 (R2007a) 7.4 18% 7.3.0.267 (R2006b) 7.3 19% 7.2.0.232 (R2006a) 7.2 20% 7.1.0.246 (R14) Service Pack 3 7.1 21% 7.0.4.365 (R14) Service Pack 2 7.04 22% 7.0.1.24704 (R14) Service Pack 1 7.01 23% 6.5.2.202935 (R13) Service Pack 2 6.52 24% 6.1.0.4865 (R12.1) 6.1 25% ... 26% 5.3.1.something (R11.1) 5.31 27% 3.2 whatever 3.2 28% 29% Example: 30% 31% v = getversion ; 32% if (v >= 7.0) 33% this code is for MATLAB 7.x and later 34% elseif (v == 6.52) 35% this code is for MATLAB 6.5.2 36% else 37% this code is for MATLAB versions prior to 6.5.2 38% end 39% 40% This getversion function has been tested on versions 6.1 through 7.10, but it 41% should work in any MATLAB that has the functions version, sscanf, and length. 42% 43% MATLAB 7.10 adds a twist. It is the first subversion that is 2 digits 44% ("10"). I need to decide how to handle this case. I can't return 7.1, 45% of course. But returning 8.0 is also problematic. 46% 47% See also version, ver, verLessThan. 48 49% Copyright 2007, Timothy A. Davis 50 51% This function does not use ver, in the interest of speed and portability. 52% "version" is a built-in that is about 100 times faster than the ver m-file. 53% ver returns a struct, and structs do not exist in old versions of MATLAB. 54% All 3 functions used here (version, sscanf, and length) are built-in. 55 56v = sscanf (version, '%d.%d.%d') ; 57v = 10.^(0:-1:-(length(v)-1)) * v ; 58