How to load multiple paths using 'loadlibrary'?
2 views (last 30 days)
Show older comments
MathWorks Support Team
on 13 Jan 2021
Answered: MathWorks Support Team
on 14 Jan 2021
I am using "loadlibrary" function to load a C++ library in MATLAB, and I have a lot of paths to include for the "includepath" parameter.
Currently, I can only use the following way to include these paths:
>> loadlibrary(..., 'includepath', path1, 'includepath', path2, 'includepath', path3, ...);
The 'includepath' doesn't accept a path array or a wildcard. Is there an easier way to include multiple paths?
Accepted Answer
MathWorks Support Team
on 13 Jan 2021
"loadlibrary" processes the input parameters individually, so arrays or wildcards will not work.
However, it may be possible to write a small script to process an array of pathnames and generate a "loadlibrary" command string that can be implemented with "eval".
Here's a simple example:
paths = genpath('\path\to\libraries');
pathArr = split(paths, ';');
includeStr = "loadlibrary('yourlib', 'yourlib.m'";
for i = 1:length(pathArr)
includeStr = strcat(includeStr, ",'includepath','",pathArr(i),"'");
end
includeStr = strcat(includeStr, ");");
eval(includeStr);
The 'includeStr' should include all the paths we would like to input to 'loadlibrary' function and then, we can simply call it using 'eval'.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical 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!