Loren on the Art of MATLAB

November 14th, 2007

What Version is Being Used?

Sometimes it's important to have code work in multiple releases of MATLAB, while still taking advantage of new features when they exist. In recent articles, I've talked about the MException class and using try/catch. Here's another tool to add to your collection: verLessThan.

Contents

ver and version

The functions version and ver allow you to query for the MATLAB version and versions of additional products, as well as extra environmental information.

v = version
v =
7.5.0.342 (R2007b)
vmat = ver('matlab')
vmat = 
       Name: 'MATLAB'
    Version: '7.5'
    Release: '(R2007b)'
       Date: '02-Aug-2007'
vsim = ver('simulink')
vsim = 
       Name: 'Simulink'
    Version: '7.0'
    Release: '(R2007b)'
       Date: '02-Aug-2007'

There is additional information supplied when I ask for the information to be displayed instead of assigning it to a variable.

ver simulink
-----------------------------------------------------------------------------
MATLAB Version 7.5.0.342 (R2007b)
MATLAB License Number: DEMO
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 2)
Java VM Version: Java 1.6.0 with Sun Microsystems Inc.
       Java HotSpot(TM) Client VM mixed mode
-----------------------------------------------------------------------------
Simulink                                           Version 7.0        (R2007b)

Trademarks
------------------
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, and xPC
TargetBox are registered trademarks and SimBiology, SimEvents, and
SimHydraulics are trademarks of The MathWorks, Inc. Other product or
brand names are trademarks or registered trademarks of their respective
holders. 

verLessThan for MATLAB versions 6.0-7.3

varLessThan started shipping with the MATLAB R2007a release. To bridge the gap back to the year 2000 and MATLAB version 6.0, look at this solution from the tech support web site. There's a link near bottom to get access to verLessThan M-file backward compatible to MATLAB 6.

References

Here are the references to the blog articles I mentioned earlier.

Other Compatibility Tools

I know there are other compatibility tools on MATLAB Central as well, such as this one from Tim Davis.

Thoughts?

We make a concerted effort to not introduce incompatibilities without good reason. We also try to supply tools to help you manage and use the new tools alongside older ones. If you have any thoughts or suggestions on the topic of managing compatibility, please share them here.


Get the MATLAB code

Published with MATLAB® 7.5

4 Responses to “What Version is Being Used?”

  1. Matt Whitaker replied on :

    Hi Loren,
    It should be noted that ver is not available in compiled code prior to R2007b. See tech solution:
    http://www.mathworks.com/support/bugreports/details.html?rp=225580

  2. Loren replied on :

    Yes Matt, that’s true. There was a bug using ver with the MATLAB Compiler and it has been fixed.

    –Loren

  3. Tim Davis replied on :

    It would be very helpful if there were a MATLAB_VERSION #define’d for use in a C/C++ mexFunction. For example:

    #if MATLAB_VERSION >= 7.3
    #define Int mxSignedIndex
    #else
    #define Int int
    #endif

    Int *p = mxGetJc ( … ) ;

    The new mx data type for an integer can’t be used in mexFunctions that attempt to port to older versions of MATLAB. Thus, I just use “long” and skip the use of mxSignedIndex that appeared in MATLAB 7.4 (or was it 7.3…? whichever …).

    The lack of a MATLAB_VERSION makes porting a mexFunction for different versions of MATLAB (both 32-bit and 64-bit) very very tricky, particularly ones that deal with sparse matrices since the mexFunction needs to know how the integers are stored inside the sparse matrix (32 or 64 bits).

    Those who write M-files don’t have to worry about this, but mexFunction authors do.

  4. Tim Davis replied on :

    In addition, the #define for MATLAB_VERSION should be ported back to older MATLAB versions, say in a #include “mex_version.h” file that could be back-ported. This mex_version.h file would figure out the MATLAB version number using details of the kind of #define’s inside the mex.h file, such as:
    #ifndef MATLAB_VERION
    #ifdef mxSignedInt

    MATLAB_version 7.3 (or whatever) to 7.5; use other
    aspects of mex.h to figure out which one.

    #else

    this is MATLAB 7.2 or earlier, etc.

    #endif

    #else

    this must be MATLAB 7.6 (or whatever) that has MATLAB_VERSION defined already

    #endif

    I’d write such a mex_version.h myself, but it would require some pretty deep analysis of the mex.h file and all the files it includes, to figure out what the best #if tests are. It would be best be done by someone at The MathWorks.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Loren Shure works on design of the MATLAB language at The MathWorks. She writes here about once a week on MATLAB programming and related topics.

  • Loren: Paul- There *are* issues depending on the sizes of ii and jj. And it’s a bit complicated, but really...
  • Loren: Bob- You don’t say what happens when you run your code. Can you please explain more. It looks like you...
  • Loren: Kishore- It is not clear to me what you are trying to actually achieve. If you want to concatenate the 4...
  • Kishore: sorry, in the previous code mat2cell(c,[19 121],[19 134],[19 84],[19 107])
  • Kishore: Hi Loren, Why does the following not work? data_classwise = [19x121 double] [19x134 double] [19x84 double]...
  • Paul Jackson: Loren, Are there any aspects of empty matrices that may be tricky when they are used as indices into...
  • Bob: Hi Lori, Im trying to process Unicode text files from more than one different locales than the standard latin...
  • Loren: Ben- The reference link in my post documents the behavior of sum([]) and prod([]) (although the prod part only...
  • Ben: Loren/Andrey, A further advantage of having sum([])==0 and prod([])==1 is that it’s consistent with array...
  • Loren: OysterEngineer- I will SO take you up on that offer. Can’t wait for a good reason to visit now....

These postings are the author's and don't necessarily represent the opinions of The MathWorks.