问题描述
如何在脚本/函数中检查已安装的MATLAB工具箱? (检查工具箱版本也不错!)当有人尝试在没有必需工具箱的情况下尝试运行脚本时,这可能会提供快速且有用的错误消息.
How would one check for installed MATLAB toolboxes in a script/function? (checking toolbox versions would also be good!) This could provide a quick and useful error message when someone attempts to run a script without a required toolbox.
想到的一个快速但粗略的解决方案是解析 ver
命令.我想知道是否有更好的方法.
A quick, albeit rough, solution that comes to mind is parsing the text output of the ver
command. I wonder if there's a better way.
一些快速搜索显示ver product
或 license
带有'test'
参数的函数可能有用,但是我找不到工具箱名称(即'Image Processing Toolbox'
)到产品名称(即'control'
)或功能名称(即).
Some quick searching revealed ver product
or the license
function with the 'test'
argument may be useful, but I could not find a mapping of toolbox names (ie. 'Image Processing Toolbox'
) to product names (ie. 'control'
) or feature names (ie. image_toolbox
).
此外,当我运行license('inuse')
时,我仅收到以下内容:
Furthermore, when I ran license('inuse')
, I only received the following:
>> a = license('inuse'); a
a =
feature: 'matlab'
user: <username>
我希望列出我可以使用的许多工具箱.
I hoped for a list of the many toolboxes I have access to.
此问题是通过尝试尽早测试同事脚本而提示的.不幸的是,它需要我目前缺少的图像处理工具箱.一条有用的错误消息将节省尝试诊断问题的时间.现在,我将等待编译后的版本,然后再对其进行测试.
This question was prompted by trying to test a co-workers script early. Unfortunately, it required the Image Processing Toolbox, which I currently lack. A useful error message would've saved time trying to diagnose the problem. Now I'll wait for a compiled version before testing it.
推荐答案
ver
功能是它仅告诉您已安装的内容,而不告诉您具有可用许可证的内容.可能会安装一个工具箱,而没有使用它的许可证(或者所有可用的许可证都可以由其他用户签出).更好的选择是 license
函数,指出)需要唯一的功能字符串" 每个工具箱.
One drawback to the ver
function is that it only tells you what's installed, not what has an available license. It's possible to have a toolbox installed and no license to use it (or all the available licenses could be checked out by other users). A better choice is the license
function, which (as you pointed out) requires a unique "feature string" for each toolbox.
这是来自现已失效的新闻组线程(链接现在无效):
Here's an older list of feature strings for various toolboxes taken from a now-defunct newsgroup thread (link is now dead):
featureStr = {'Aerospace_Blockset'; ...
'Aerospace_Toolbox'; ...
'Bioinformatics_Toolbox'; ...
'Communication_Blocks'; ...
'Communication_Toolbox'; ...
'Compiler'; ...
'Control_Toolbox'; ...
'Curve_Fitting_Toolbox'; ...
'Data_Acq_Toolbox'; ...
'Database_Toolbox'; ...
'Datafeed_Toolbox'; ...
'Dial_and_Gauge_Blocks'; ...
'Distrib_Computing_Toolbox'; ...
'Econometrics_Toolbox'; ...
'EDA_Simulator_Link_DS'; ...
'Embedded_Target_c166'; ...
'Embedded_Target_c2000'; ...
'Embedded_Target_c6000'; ...
'Embedded_Target_MPC555'; ...
'Excel_Link'; ...
'Filter_Design_HDL_Coder'; ...
'Filter_Design_Toolbox'; ...
'Fin_Derivatives_Toolbox'; ...
'Financial_Toolbox'; ...
'Fixed_Income_Toolbox'; ...
'Fixed_Point_Toolbox'; ...
'Fixed-Point_Blocks'; ...
'Fuzzy_Toolbox'; ...
'GADS_Toolbox'; ...
'IDE_Link_MU'; ...
'Identification_Toolbox'; ...
'Image_Acquisition_Toolbox'; ...
'Image_Toolbox'; ...
'Instr_Control_Toolbox'; ...
'Link_for_Incisive'; ...
'Link_for_ModelSim'; ...
'Link_for_Tasking'; ...
'Link_for_VisualDSP'; ...
'MAP_Toolbox'; ...
'MATLAB'; ...
'MATLAB_Builder_for_dot_Net'; ...
'MATLAB_Builder_for_Java'; ...
'MATLAB_Distrib_Comp_Engine'; ...
'MATLAB_Excel_Builder'; ...
'MATLAB_Link_for_CCS'; ...
'MATLAB_Report_Gen'; ...
'MBC_Toolbox'; ...
'MPC_Toolbox'; ...
'NCD_Toolbox'; ...
'Neural_Network_Toolbox'; ...
'OPC_Toolbox'; ...
'Optimization_Toolbox'; ...
'PDE_Toolbox'; ...
'Power_System_Blocks'; ...
'Real-Time_Win_Target'; ...
'Real-Time_Workshop'; ...
'RF_Blockset'; ...
'RF_Toolbox'; ...
'Robust_Toolbox'; ...
'RTW_Embedded_Coder'; ...
'Signal_Blocks'; ...
'Signal_Toolbox'; ...
'SimBiology'; ...
'SimDriveline'; ...
'SimElectronics'; ...
'SimEvents'; ...
'SimHydraulics'; ...
'SimMechanics'; ...
'Simscape'; ...
'SIMULINK'; ...
'Simulink_Control_Design'; ...
'Simulink_Design_Verifier'; ...
'Simulink_HDL_Coder'; ...
'Simulink_Param_Estimation'; ...
'SIMULINK_Report_Gen'; ...
'SL_Verification_Validation'; ...
'Spline_Toolbox'; ...
'Stateflow'; ...
'Stateflow_Coder'; ...
'Statistics_Toolbox'; ...
'Symbolic_Toolbox'; ...
'SystemTest'; ...
'Video_and_Image_Blockset'; ...
'Virtual_Reality_Toolbox'; ...
'Wavelet_Toolbox'; ...
'XPC_Embedded_Option'; ...
'XPC_Target'};
这涵盖了许多常见的功能,但并不详尽,也不包含较新工具箱的功能字符串.对于所有MathWorks工具箱,似乎没有任何易于使用的当前功能字符串列表.我相信您可以在许可证文件的"INCREMENT"行中找到它们,或(),您可以从给定的工具箱中调用函数,然后使用license('inuse')
从显示的列表中获取功能字符串当前正在使用的工具箱的数量.但是,以上两个选项都已经需要可用的许可证.
This covers many of the common ones, but isn't exhaustive and doesn't include feature strings for newer toolboxes. There doesn't appear to be any readily-available list of current feature strings for all MathWorks toolboxes. I believe you can find them on the "INCREMENT" lines in a license file, or (as vlee mentions in a comment) you can call a function from a given toolbox and then use license('inuse')
to get the feature string from the displayed list of toolboxes currently being used. However, both of the above options require an available license already.
使用上面的功能字符串列表和功能 license
,您可以检查要使用许可证的工具箱.以下代码检查上面整个列表的许可证:
Using the above list of feature strings and the function license
, you can check which toolboxes you have a license to use. The following code checks for licenses for the entire list above:
index = cellfun(@(f) license('test', f), featureStr);
availableFeatures = featureStr(logical(index));
但是,以上内容只是确认许可证存在,而不是可以签出.许可证可能已过期,或者其他用户可以检出所有可用许可证.为了绝对确定您将能够使用可用的工具箱,实际上您可以尝试签出所需许可证的许可证并进行测试以查看是否成功.以下代码尝试检出上面找到的所有可用工具箱的许可证:
However, the above just confirms that the license exists, not that it can be checked out. The license could have expired or all the available licenses could be checked out by other users. To be absolutely certain that you will be able to use the available toolboxes, you can actually try to check out a license for the ones you need and test to see if you were successful. The following code attempts to check out a license for all the available toolboxes found above:
index = cellfun(@(f) license('checkout', f), availableFeatures);
checkedOutFeatures = availableFeatures(logical(index));
警告语!:
Jason S在下面的评论中提到,故意放弃许可证是个坏主意,因为要等到您关闭MATLAB后才能发布许可证. 您只应签出您知道给定应用程序所需的许可证!通常,只有在尝试使用给定工具箱中的功能之前,才签出许可证.例如:
As Jason S mentions in a comment below, it's a bad idea to check out licenses willy-nilly, since they won't be released until you close MATLAB. You should only check out a license that you know you will need for a given application! Normally, licenses aren't checked out until you try to use a function from a given toolbox. For example:
>> license('inuse')
matlab
>> gaussFilter = fspecial('gaussian'); % An Image Processing Toolbox function
>> license('inuse')
image_toolbox
matlab
这篇关于如何检查脚本/函数中已安装的MATLAB工具箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!