Is there a workaround to conditionally import java class to import list in MATLAB?
Show older comments
I guess the answer is no, but I'd like to try.
Is there a workaround to conditionally import java class to import list in MATLAB? The documentation of MATLAB simply denies it.
> Do not use import in conditional statements inside a function. MATLAB preprocesses the import statement before evaluating the variables in the conditional statements.
function func1()
...
if A
import ij.process.LUT
end
...
end
I wanted to implement something like this in a function, because it is not guaranteed that ij.process.LUT is within MATLAB's scope. Simply calling import ij.process.LUT will cause an error in some scenarios.
The following trick did not work, since it appears that MATLAB evaluates import statements before actually running code.
function func2()
...
try
if A
import ij.process.LUT
end
catch
end
...
end
Accepted Answer
More Answers (1)
Kouichi C. Nakamura
on 17 May 2018
Categories
Find more on Introduction to Installation and Licensing 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!