Identify Matlab Version used to create a .m file

Is there any way of identifying with which version of matlab a particular .m file has been created?

 Accepted Answer

No. You do not need MATLAB to create .m files. The MATLAB editor does not insert any meta data about its version in the .m file.
A related question is trying to determine the version of MATLAB that the .m file was created FOR. In other words, which versions of MATLAB can the .m file be run on. MATLAB has introduced some "syntax" changes (e.g., ~ as a placeholder and parfor). You could use the presence of these changes to roughly track a version. Other things like new functions are not possible. You cannot tell from looking at the code if a function call is a call for a new built-in function or a old function taken from the FEX.

4 Comments

+1. One addition: A reliable programmer has written such important information to the comment section on top of the code.
If e.g. the function needs a specific behaviour of STRCMP, which has changed in 2010b, it is essential to explain this explicitely.
I haven't done this in the past, but I have been realizing that we cannot count on backwards compatibility from TMW (i.e., your STRCMP example). If I could get myself to do good and frequent unit testing, then I would modify my version control system to include a tested under comment in the header.
@Daniel: Does this work seamlessly using different Matlab releases for testing? After changing the code, the former successful tests are not valid anymore. So you need something like:
$Tested: Version from 23-Nov-2010 23:10:17 tested under Matlab 2008a$
$Tested: Version from 23-Nov-2010 23:10:17 tested under Matlab 2009b$
While all messages like $Tested: version from 22-Nov...$ should disappear automatically.
@Jan, I don't currently reliably unit test and I definitely don't unit test on multiple releases yet, so I am not sure how I would do handle the commenting part. I am pretty sure keywords ("Tested" in your example) can only have one value (although it can be a multi-line value) so it isn't as easy as your example. That said, I don't see any reason that you couldn't get something like that to work. If you invoked the multi-release unit test from a BASH script you could have the script keep appending things to the keyword replacement string.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!