如何测试最新版本的MATLAB? [英] How to test for recent-enough version of MATLAB?
问题描述
我要实现的功能需要知道MATLAB的当前版本是否至少是最新的R2014a
.
A function I want to implement needs to know whether the current version of MATLAB is at least as recent as R2014a
.
是否存在受支持的强大方式来执行此检查?
Is there a robust, supported way to perform this check?
(具有强大,受支持" 的意思是说,我对脆弱的hack(例如,解析由版本返回的字符串等)不感兴趣.
(With "robust, supported" I mean to say that I'm not interested in fragile hacks such as parsing the string returned by version, etc.)
BTW,在这种情况下,我想要进行此检查的原因是要知道我可以使用功能matlab.lang.makeUniqueStrings
.如果有一种可靠,受支持的方法来检查此功能的可用性,我将使用它来代替测试当前的MATLAB是否足够.不幸的是,似乎没有这样的检查:exist
对我可以为该函数的名称提供的每个变体都返回false.再说一次,我可以想到脆弱的骇客模仿一个适当的测试(例如which('matlab.lang.makeUniqueStrings')
),但是它们并没有比我上面提到的版本测试骇客更好.
BTW, in this case, the reason I want this check is to know that I can use the function matlab.lang.makeUniqueStrings
. If there were a robust, supported way to check for the availability of this function, I'd use it instead of testing that the current MATLAB is recent enough. Unfortunately, there doesn't seem to be such a check: exist
returns false to every variant I can come up for the name of this function. Again, I can think of fragile hacks to mimic a proper test (e.g. which('matlab.lang.makeUniqueStrings')
), but they're hardly better than the version-testing hacks I alluded to above.
我发现的最佳解决方案是在try-catch
块中使用matlab.lang.makeUniqueStrings
运行命令.这仍然是一个脆弱的技巧,因为MATLAB
不能提供一种强大的内置方式来捕获特定的异常!
The best solution I have found is to run the command using matlab.lang.makeUniqueStrings
within a try-catch
block. This is still a fragile hack, because MATLAB
does not offer a robust, built-in way to catch specific exceptions!
IOW,这都是关于选择最不可怕的黑客.测试当前版本是否足够新(即使此测试是易碎的hack),至少具有足够通用的优点,可以坚持某些功能,并且至少包含易碎的hacky代码的泛滥.
推荐答案
我会使用 verLessThan
函数:
I would use the verLessThan
function:
verLessThan('matlab', '8.3')
如果您使用的当前版本早于8.3(R2014a),则返回true(1),否则返回false(0).无需字符串解析.
This will return true (1) if the current version you are using is older than 8.3 (R2014a) and false (0) otherwise. No string parsing required.
然后您可以像这样使用它:
You could then use it like so:
if ~verLessThan('matlab', '8.3')
% Run code using matlab.lang.makeUniqueStrings
end
这篇关于如何测试最新版本的MATLAB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!