I was given some matlab code. How do I figure out what toolboxes are necessary to run the code?
5 views (last 30 days)
Show older comments
When a user is provided matlab code how does the user figure out what toolboxes are necessary to run the code? Does matlab have a online code analyser inwhich a user can have the code analyzed to see which toolboxes are necessary?
0 Comments
Answers (4)
bio lim
on 15 Jul 2015
There might be better and easier ways, but I usually run the code first. If there are some undefined functions, or errors regarding functions etc, I usually check online and figure out which Toolboxes are necessary.
0 Comments
John D'Errico
on 15 Jul 2015
Checking your code for dependencies on functions that you don't have is a terribly difficult thing to do well, since someone else might have written a code that uses their own version of something they may have named lsqlin, or fmincon. If two functions have the same name, any dependency analyzer will be unable to know the difference.
So the very best way to know is to ask the source person!
You could ask them to run the code, and check the results from depfun.
David Andres
on 15 Jul 2015
2 Comments
Stephen Farrington
on 27 Feb 2024
It's even worse than that, since execution will halt at the first dependency on an unlicensed Toolbox. You can't know which other Toolboxes you may require until you license each one in succession. Laughably, Matlab's suggestion for solving this is to run the code "on a system that has all Toolboxes licensed" to determine which ones the code uses.
Steven Lord
on 27 Feb 2024
That is one possibility for small, simple code.
The documentation page to which I linked back in July 2015 offers two additional suggestions regarding dependencies, one of which is for dependencies inside a folder and one of which is the matlab.codetools.requiredFilesAndProducts function for doing exactly what the original poster asked.
As an example, what products are required to run fmincon from Optimization Toolbox?
[fileList, productList] = matlab.codetools.requiredFilesAndProducts('fmincon');
fprintf("Running fmincon requires %d products.\n", numel(productList))
fprintf("Required product: %s\n", productList.Name)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!