No BSD License  

Highlights from
vernum.m

3.0

3.0 | 7 ratings Rate this file 0 Downloads (last 30 days) File Size: 1.16 KB File ID: #11602

vernum.m

by Dave Ciochetto

 

30 Jun 2006 (Updated 30 Jun 2006)

vernum - returns the current version of Matlab as a number

| Watch this File

File Information
Description

vernum - returns the current version of Matlab as a number

30 June 2006 - Created
by David S. Ciochetto and Audrey Barnett, Dalhousie Oceanography
30 June 2006 (Last modified) by David S. Ciochetto

This function gets the current version of matlab and converts it to a real number through the first decimal point. It is intended to be used to delimit cases where code is specific to particular Matlab versions. It is particularly useful for < or > a specific version such as when someone writes to you and says hey, this does not work for Matlab 3... you can use vernum in your code to add a patch with case or if statements to write code that works for the older versions.

It is intended to make detection of the version automatic in your code so it keeps the users of your scripts happy since they do not need to go in and fix the code for their specific version.

Example
if vernum < 7.1 % The below works for Matlab versions earlier than 7.1
  % Add code
else % works for newer code
  % Add fancy code here
end

Acknowledgements
This submission has inspired the following:
getversion: find MATLAB version number as a double
MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
30 Jun 2006 Jos x

Simply
vernum = ver('matlab') ;
vernum = str2double(vernum.Version) ;
would do this better.

01 Jul 2006 kristjan jonasson

Too simple functionality to place here (and can be done simpler).

05 Jul 2006 B L

Both comments are true, but the methods suggested do not return a real number as this code does. They will return a character string.

If you want to make code that works for all versions prior to a particular release, that is where I see the value in this code. Plus you don't have to remember how to do it, just the code.

It is simple, only two lines, but useful.

05 Jul 2006 Sergei Koptenko

1) There are infinite number of simple useful two-liners that can be created in Matlab. Add to that an equal number of three and four-liners and you will see how FEX becomes a huge pile of ?simple but useful? junk.
2) Anonymous comments ought to be ignored by default. Serious participants have no reason to hide its face. We are not dealing drugs here.

22 Jul 2006 AnonToYou Hah

Will the proposed 'simpler' solution from Jos work for the first version of Matlab I used ... ???
5.2.1.1420

01 Nov 2007 Tim Davis

Jos's comment about computing vernum will work on any MATLAB that has struct's. However, the whole point of a function like this is that it must work on very old MATLAB releases, including very old MATLAB's that do not have structs.

I think the .Version field returned from ver might be a string of the form 'A.B.C', in which case Jos' suggestion will fail completely.

In any case, "ver" is about 100 times slower than "version" (try it), an important consideration if this code is called inside a heavily-called function. That critique applies to the new "verLessThan" function in MATLAB, too, by the way.

So a well-written code, like this, must not use "ver".

The "version" function is likely to exist on much older MATLAB releases than "ver", since the former does not use structs.

The real question, though is this: will this code work on MATLAB 1, 2, 3, 4, 5, ...? How far back has it been tested?

I rate it a 4 because the code should be cleaned up a bit, the comments ("see also", for example) are lacking, and (mostly) because it isn't clear from the documentation how far back the code has been tested. It would also be nice to be able to distinguish between 7.0.1 and 7.0.4.

I have to strongly disagree with Sergei's comment. The real usefulness of this code is that it can (or at least should) be written *very* carefully so that it will run on, say, MATLAB 3. Assuming that has been done, that makes this code useful for those of us who no longer have a copy of MATLAB 3.

Getting these 2 lines right is *not* a trivial thing, as Sergei claims it to be.

12 Apr 2010 Jan Simon

For 2010a this replies 7.10, which equals 7.1!
Faster and simpler (and less than 2 lines):
  VersionNumber = sscanf(version, '%f', 1)
But this fails for v7.10 also, but this get catch it:
  [10000, 100, 1] * sscanf(version, '%d.', 3)
e.g. 6.5.1 => 60501. This is monotonically increasing and unique - but still just another strange method.

Please login to add a comment or rating.
Updates
30 Jun 2006

Add a ';' to prevent unwanted output to screen.

Tag Activity for this File
Tag Applied By Date/Time
path Dave Ciochetto 22 Oct 2008 08:31:44
directories Dave Ciochetto 22 Oct 2008 08:31:44
files Dave Ciochetto 22 Oct 2008 08:31:44
matlab version number as a real value Dave Ciochetto 22 Oct 2008 08:31:44

Contact us at files@mathworks.com