f



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.

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

3 Replies
535 Views

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
directory).

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();

0
thommo101 (94)
3/13/2006 7:06:12 AM
hey,
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.

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

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
    javaaddpath(pwd);
end

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

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