I'm using r2012b with MATLAB compiler version 4.18.
Running the following script…
import java.util.HashMapa1 = java.util.HashMap()a2 = HashMap()
from the MATLAB environment produces expected results, i.e.:
a1 ={}a2 ={}
However, if I compile the same code and attempt to run it, I get the following error:
a1 ={}Undefined function or variable 'HashMap'.Error in test1 (line 4)
Looks like we have to specify full class names for the compiled code to work, which is a problem as we can't simply compile our existing working MATLAB code without modifying it first.
Note that I'm seeing the same with other java build-in classes (not only HashMap) as well as all other (user-defined) classes I've tried. Calling a static java method gives a similar error in the compiled code only, i.e.:
Undefined variable "Collections" or class "Collections.max".Error in test1 (line 11)
Best Answer