calling java from matlab #6

hi everyone,

Does anyone know how to reference a user-defined Java class from
Matlab? If so should the file be precompiled outside of Matlab first?
I have the Java class file folder added to the class path, and used
"import MyClass", but this doesn't work.

The error message says
Arguments to IMPORT must either end with ".*" or else specify a fully
qualified class name: "MyClass" fails this test.

3/13/2006 7:05:23 AM
comp.soft-sys.matlab 211265 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

3 Replies

Similar Articles

[PageSpeed] 26

The class must be precompiled into a valid .class file. This file must
be on the java path

(can use javaaddpath(pwd) and include the file in the current working

Then you just call the constructor as the name of the file,

ie if you had a class Foo:

in matlab:

foo_object = Foo;
foo_string = Foo.toString();

thommo101 (94)
3/13/2006 7:06:12 AM
also note that in some cases afterr adding java path to Matlab you need
to restart the matlab and just then the matlab loading to the
enviornment your adittional java .class files.

alex.frid (54)
3/13/2006 8:09:11 AM

I;ve found the opposite... using javaaddpath adds the path to your
dynamic java path.. and hence needs to be invoked every time the code
is run. However if you are going to keep your Java classes in one
location, you can edit the classpath.txt in the
<$MATLABROOT\toolbox\local> directory.

However, for our case where we are creating deployable Matlab exes, we
need to have a bit of code at the start of each mainline taht says:

if isdeployed

and then include any required Java with the exe. Its a shame its not
bundled like .mex files are!

thommo101 (94)
3/13/2006 8:36:02 AM