How to check the latest version of MATLAB?

The function I want to implement is to know if the current version of MATLAB is at least the latest as R2014a .

Is there a reliable, supported way to perform this check?

(With "reliable, supported", I want to say that I am not interested in fragile hacks, such as parsing a string, a returned version, etc.)


BTW, in this case, the reason I want this check is to know that I can use the matlab.lang.makeUniqueStrings function. If there was a reliable, supported way to check for the existence of this function, I would use it instead of checking that the current MATLAB is fairly recent. Unfortunately, there seems to be no such check: exist returns false for every option I can find for the name of this function. Again, I can think of fragile hacks to emulate the right test (for example, which('matlab.lang.makeUniqueStrings') ), but they are hardly better than the version checking versions I mentioned above.

The best solution I've found is to run the command with matlab.lang.makeUniqueStrings in a try-catch . It's still fragile to hack because MATLAB does not offer a reliable built-in way to detect certain exceptions!

IOW, all about choosing the least terrible hack. Testing that the current version is recent enough (even if this test is a fragile hack), at least tends to be general enough to stick to some function and at least contain the distribution of fragile, hacked code.

+8
matlab
source share
6 answers

I would use the verLessThan function:

 verLessThan('matlab', '8.3') 

This will return true (1) if the current version you are using is older than 8.3 (R2014a) and false (0) otherwise. No parsing of strings is required.

Then you can use it like this:

 if ~verLessThan('matlab', '8.3') % Run code using matlab.lang.makeUniqueStrings end 
+17
source share

If you only need to care about the relatively recent versions, use the verLessThan command. However, verLessThan was introduced around 2006 or so; if you need to support versions older than this, you will need to use the output of the version command.

Alternatively, you can firmly check for the presence of matlab.lang.makeUniqueStrings . First, use m = meta.package.fromName('matlab.lang') to retrieve the package related meta.package object. If m empty, the package does not exist. Assuming m not empty, check the FunctionList m property to see if makeUniqueStrings is makeUniqueStrings . (There is also a ClassList property).

Finally, MATLAB offers a way to catch certain exceptions. Instead of a simple catch use catch myError . The variable myError will be an object of type MException , available in the catch . You can test the exception properties of identifier and message exceptions and handle different exceptions accordingly, including re-removing the unhandled ones.

+7
source share

You can use the MATLAB version command for your test -

 ['Release R' version('-release')] 

Run Example -

 >> ['Release R' version('-release')] ans = Release R2012a 

Check if your version of MATLAB is latest (R2014a) -

 strcmp (version('-release'),'R2014a') 

The above command will return 1 if it is the latest version, otherwise it returns 0 .

+3
source share

The best way is to use the version command and parse the string accordingly.

 [vd] = version 

Take a look at the result of R2014a and set the appropriate values.

+2
source share

An example of what Sam had in mind:

 try %// call to matlab.lang.makeUniqueStrings catch ME %// (use regexp here to include support for Octave) if strcmpi(ME.identifier, 'MATLAB:undefinedVarOrClass') error('yourFcn:someID',... 'matlab.lang.makeUniqueStrings is not supported on your version of MATLAB.'); else throw(ME); end end 

Reliability until MathWorks changes the ID string.

As a final note: checking features is not enough: what if MathWorks decides to change the function signature? Or a list of output arguments? Or..?

In a language that in itself is not reliable, there is no truly reliable method. Be as reliable as the language allows, but no more.

+2
source share

Testing the version number is hardly a good idea. You should always check for features and never for versions if you really want reliability (and portability at the same time).

What happens if one of the features you need is removed from a future version of Matlab? Or how does it work? (this is much more common than might be expected). Or, if someone wants to use your code in a Matlab compatible system that has the features your code needs?

There are several autoconf macros related to Matlab (although I have never used them). Or you can write your own checks in the Matlab language.

0
source share

All Articles