MATLAB Answers

how to test if toolbox exists?

조회 수: 178(최근 30일)
C Lira
C Lira 3 May 2012
댓글: Walter Roberson 14 Mar 2016
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?

  댓글 수: 0

Sign in to comment.

답변(4개)

Walter Roberson
Walter Roberson 3 May 2012
For example,
license('test', 'image_toolbox')

  댓글 수: 2

Mohammad Nazrin Jumali
it says '1', what does it mean?
Walter Roberson
Walter Roberson 14 Mar 2016
It means the license does exist.

Sign in to comment.


Geoff
Geoff 3 May 2012
Try this:
v = ver;
has_fsolve = any(strcmp(cellstr(char(v.Name)), 'Optimization Toolbox'));
Or more specifically:
has_fsolve = ~isempty(which('fsolve'));

  댓글 수: 2

Jan
Jan 3 May 2012
{v.Name} is nicer than "cellstr(char(v.Name))".
Geoff
Geoff 4 May 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.

Sign in to comment.


Image Analyst
Image Analyst 3 May 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.

  댓글 수: 0

Sign in to comment.


Reza Ahmadzadeh
Reza Ahmadzadeh 29 Jun 2015
You can use the existing function in FileExchange called isToolboxAvailable . The usage is as follows:
result = isToolboxAvailable('image processing toolbox','error');

  댓글 수: 1

Kjartan Andersen
Kjartan Andersen 27 Feb 2016
Not a good idea to have an external functionality to check for dependencies. What if the user doesn't have this tool?

Sign in to comment.

태그

제품


Translated by