how to test if toolbox exists?

76 visualizaciones (últimos 30 días)
C Lira
C Lira el 3 de Mayo de 2012
Comentada: Farid el 16 de Ag. de 2022
I am writings some code that I wish to distribute open source. Within my code, I'd like to check if the end-users have fsolve in their installation and if not, use fzero. I'd rather the end-user not get ugly messages about functions not existing, and beginners will be so confused about what to do to fix the error, or they will hate Matlab. Is there a way that this can be implemented easily?

Respuestas (4)

Walter Roberson
Walter Roberson el 3 de Mayo de 2012
For example,
license('test', 'image_toolbox')
  11 comentarios
Walter Roberson
Walter Roberson el 15 de Ag. de 2022
Note that 'Neural_Network_Toolbox' is the old name for Deep Learning Toolbox, and the old name is still used internally for license capabilities.
If you want to find out whether Deep Learning Toolbox is installed, then
ver('nnet')
----------------------------------------------------------------------------------------------------- MATLAB Version: 9.12.0.2027246 (R2022a) Update 4 MATLAB License Number: Operating System: Linux 5.4.185-0504185-generic #202203160950 SMP Wed Mar 16 14:00:16 UTC 2022 x86_64 Java Version: Java 1.8.0_292-b10 with AdoptOpenJDK OpenJDK 64-Bit Server VM mixed mode ----------------------------------------------------------------------------------------------------- Deep Learning Toolbox Version 14.4 (R2022a)
Again, 'nnet' is an internal name for this purpose, derived from the old marketing name Neural Network Toolbox
If ver shows the toolbox but license test does not show it, then go to the command window and Help -> Licensing -> Update Current Licenses... to make sure the license is up to date (in case features got added to the license after the file was downloaded.)
Farid
Farid el 16 de Ag. de 2022
@Walter Roberson, @Image Analyst. Thank you big time!

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 3 de Mayo de 2012
Here's the code I use:
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
You'll need to adapt it for any toolboxes that you want to check.

Geoff
Geoff el 3 de Mayo de 2012
Try this:
v = ver;
has_fsolve = any(strcmp(cellstr(char(v.Name)), 'Optimization Toolbox'));
Or more specifically:
has_fsolve = ~isempty(which('fsolve'));
  2 comentarios
Jan
Jan el 3 de Mayo de 2012
{v.Name} is nicer than "cellstr(char(v.Name))".
Geoff
Geoff el 4 de Mayo de 2012
Oh, thanks =) I get a bit baffled sometimes when things look like the right type but return multiple answers. That's a much nicer syntax.

Iniciar sesión para comentar.


Reza Ahmadzadeh
Reza Ahmadzadeh el 29 de Jun. de 2015
You can use the existing function in FileExchange called isToolboxAvailable . The usage is as follows:
result = isToolboxAvailable('image processing toolbox','error');
  1 comentario
Kjartan Andersen
Kjartan Andersen el 27 de Feb. de 2016
Not a good idea to have an external functionality to check for dependencies. What if the user doesn't have this tool?

Iniciar sesión para comentar.

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by