MATLAB: Does the first call to JAVAADDPATH and IMPORT not work from within a function

importjavajavaaddpathMATLAB

when I run my function that calls javaaddpath and import for the first time I receiver the following error:
??? Error: File: importtest.m Line: 5 Column: 8
Arguments to IMPORT must either end with ".*"
or else specify a fully qualified class name: "package.class" fails this test.
The second call doesn't fail.

Best Answer

This enhancement has been incorporated in Release 2010b (R2010b). For previous product releases, read below for any possible workarounds:
This behavior is not a bug and is due to a change in import in MATLAB 7.0 (R14).
To work around this issue run the javaaddpath and the import command in script before running the function. If you would like to compile your code. Run JAVAADDPATH and IMPORT in the startup.m file. To know more about startup, run
doc startup
in MATLAB.